Smidge icon indicating copy to clipboard operation
Smidge copied to clipboard

Control the minified address?

Open cindro opened this issue 8 years ago • 10 comments

Is there a way to control the url? so instead of Smidge creating /sb/js.js.v1 for my js files, can I tell it to give me a different url e.g /js ?

This was possible with previous MVC 5 I think, let know if Smidge has this.

cindro avatar Jun 21 '16 11:06 cindro

Currently it doesn't have this as a configuration option, but you could replace the IUrlManager at startup with your own which is what generates them.

  • https://github.com/Shazwazza/Smidge/blob/master/src/Smidge/CompositeFiles/IUrlManager.cs
  • https://github.com/Shazwazza/Smidge/blob/master/src/Smidge/CompositeFiles/DefaultUrlManager.cs

We could/should of course make the pattern configurable via options to make this easier.

Shazwazza avatar Jun 23 '16 07:06 Shazwazza

OOTB currently you can tweak a couple of things without replacing the full IUrlManager, you can do this at startup:

services.AddSmidge(_config)
                .Configure<SmidgeOptions>(options =>
                {
                      //configure some options
                })

The SmidgeOptions is defined here: https://github.com/Shazwazza/Smidge/blob/master/src/Smidge/Options/SmidgeOptions.cs which has some url manager options that you can set: https://github.com/Shazwazza/Smidge/blob/master/src/Smidge/CompositeFiles/UrlManagerOptions.cs

So you can control some parts of the path but not the full pattern - I can add this to the options for 1.0.0 release though

Shazwazza avatar Jun 28 '16 19:06 Shazwazza

Thank you for the retailed reply, I think it would be a great feature to have for version 1.0.0 imho.

cindro avatar Jun 28 '16 19:06 cindro

The way Smidge works is that it can do two things:

  • Pre-defined bundles - which is what many people will choose to use
  • Runtime 'bundles' - this allows you to declare dependencies in your views or elsewhere to dynamically build up a collection of dependencies - these are named according to a hash and are called Composite bundles (i.e. the url would look like depending on the number of files: /sc/c61531b5.2512be3b.bb1214f7.a21bd1fd.js.v1

In both cases, Smidge will hard cache the results on disk based on the current version. So the URL will always require these parts: Name, Extension, Version So that Smidge can find the cached disk versions since we don't want to re-bundle/minify/etc... if it's already done even if the web app restarts.

Currently you can already specify the CompositeFilePath and the BundleFilePath in Options on startup, these default to: "sc" (stands for Smidge Composite) and "sb" (stands for Smidge Bundle). As these are routes, Smidge needs to know these route prefixes at startup. If you want your bundle paths to start with "/js/" instead of "/sb/", you can do this now by modifying the BundleFilePath on startup. But if you have a bundle called "js" and you change this path to be "js", then you'll end up with a url of: /js/js.js.v1 which will work but depends on if you are ok with that.

I've looked into making these urls more configurable but the end result is a bit messy for little benefit. I can look into this some more after 1.0.0 is released if you have further feedback regarding this?

Shazwazza avatar Jul 01 '16 13:07 Shazwazza

@Shazwazza Don't worry about it, I thought that this would have been an easy little feature, but if the end the result is messy its definitely not worth it. Thank you so much for the explanation and your efforts. Smidge is perfect as it is!

cindro avatar Jul 01 '16 15:07 cindro

Ok cool, well you can certainly change the prefix path :) I'll keep thinking about this Post 1.0.0 rtm

Shazwazza avatar Jul 01 '16 15:07 Shazwazza

Hi @Shazwazza I hope you are doing well mate. Thanks for all your hard work. I realize this issue is from 2016, but I found it when researching why the Umbraco Backoffice was not loading. Turns out - the process used here modifies the file extension and when working behind an enterprise firewall these files are blocked. They are blocked because they are of an unknown exstension.

May I ask, why not keep the original extension?

For your example above:

/sc/c61531b5.2512be3b.bb1214f7.a21bd1fd.js.v1

Could instead be:

/sc/c61531b5.2512be3b.bb1214f7.a21bd1fd.v1.js <- ".js"

Either way, thank you for the explanation on how we can possibly replace this functionality. I'm going to try it in an Umbraco 10 installation.

All the best!

markadrake avatar Sep 23 '22 14:09 markadrake

Smidge changes the file extension of these files, and requests to these files (of an unknown and unapproved file ext) are denied. Thus, nobody can use the Umbraco backoffice.

I've deployed the application in Debug mode for the time being.

I would politely request a way to adjust the file naming convention, so that we are able to keep the original file extension.

All the best,

markadrake avatar Sep 26 '22 21:09 markadrake

Hi Mark,

I understand your issue and will need to look into how we can make this configurable (if it's not already). Sorry been busy this week but I'll dive into it very soon.

Shazwazza avatar Oct 06 '22 20:10 Shazwazza

@Shazwazza thank you mate! If and when you get the chance, I submitted a pull request for this feature. I'm not a back-end developer. I suspect my code output isn't up to standards but would love the chance to finish the commit with your help. All the best! Thanks,

markadrake avatar Oct 07 '22 00:10 markadrake