TL;DR: IItemTransform
isn't getting executed when a minified file already exists in the same folder as the original (non-minified) file.
Problem explanation
I'm having this issue mainly because of CSS relative image references. If you used IItemTransform
with Javascript files, the same applies.
This is what I'm using:
- I'm using Visual Studio with Web Essentials addin to have support for LESS files
- I'm writing LESS files and have Web Essentials addin automatically minify files on save
- I'm also using bundling and minification in my project
- When creating CSS bundles I'm using
CssRewriteUrlTransform
to make CSS URLs absolute (i.e. background images) so that images still work after bundling several CSS files together
Nothing unusual here so far, but it doesn't work.
What seems to be the problem?
The way that bundling and minification works is it tries to avoid excessive processing. This means that when a minified file exists in the same folder as the original one it won't run its own minification and rather serve existing file.
This would be all right as long as it would at least run transforms over those preexisting minified files. But it doesn't. So I end up with relative URLs in a bundle which breaks pretty much all those resources.
Workarounds
- Always provide absolute paths in LESS files
- Disable file minification on save in Web Essentials settings
- Refer to minified files when defining my bundles because they don't have a minified version (*.min.css doens't have a *.min.min.css) so minifier actually picks up the file and minifies while also running transformations over it.
From the standpoint of my development process and tools used (and configured the way they are) this looks like a bug. If those files would be the result of the same minification process this wouldn't be a bug at all as transformations would be executed when minification would execute. It's true that such functionality doesn't exist and likely never will as app would need write permissions to make it work. Outcome: this is a bug. Existing minified files should be processed through transformations before being cached.
Question
Is it possible to somehow convince bundling and minification to either:
- not use existing minified file versions
- run transformations over existing minified versions
IBundleBuilder
could work, similar to this SO post. – TouchandgoIBundleTransform
I wouldn't be able to change URL relative paths to absolute ones any more as I won't know where original files resided before bundling... – Trout