Disable the cache if files changed

Sep 19, 2015 at 2:27 AM
Deploy -
if (date_modify("style.min.css") != date_modify("style1.css") || date_modify("style.min.css") != date_modify("style2.css")) 
{
    // files changed, minify
    ["style1.css", "style2.css"] => style.min.css
    if (production) 
    {
        // set version parameter
        setVerion("css"); // newVersion = oldVersion + 1;
    }
    
} else {
    // do nothing
}
Masterpage -
<%
version = getVerion("css"); // from database or cache
%>

<link rel="stylesheet" href="/css/style.min.css?v=<%=version%>" type="text/css">
1) How to disable minification if the files have not changed?
2) How to add a version get-parameter during compression and deploy to production?
Coordinator
Sep 22, 2015 at 7:46 AM
Hello,

I'm not sure why you would want either of these TBH.
I guess you could add something in MSBUILD to check all the files and not invoke the compressor if none of the dates have changed, but that is not the responsibility of the compressor itself.
How would you distinguish between "really do it" and "only do it if files have changed"?

For the second one, version of what? What are you trying to achieve?
The line you have looks fine - you get a version from somewhere and you append it to the link - are you saying you want the version IN the css?
Then you need something that places it in the original css files and THEN calls compress and it will be retained.
Again, it is not the job of the compressor to be injecting extra info somehow - it is there to compress what you already have.
Sep 23, 2015 at 1:14 PM
freeranger wrote:
For the second one, version of what? What are you trying to achieve?
Hello,

CSS and JS files are stored in the browser cache. In my case, a random GET-parameter prevent caching css and js files if they really have been changed.
Coordinator
Sep 23, 2015 at 1:49 PM
Edited Sep 23, 2015 at 1:50 PM
CSS and JS files are stored in the browser cache. In my case, a random GET-parameter prevent caching css and js files if they really have been changed.
I don't understand why this would be a concern of YUICompressor.NET.

in your code you have :
<%
version = getVerion("css"); // from database or cache
%>

<link rel="stylesheet" href="/css/style.min.css?v=<%=version%>" type="text/css">
which is great! that's using cache busting via querystring params.

so the version is actually a web.config value. Not something from YUICompressor.NET which .. er .. injects/sticks some number right into the files, themselves.

eg.
<appSettings>
    <add key="version" value="foo1"/>
</appSettings>
that's my opinion, on this.
Coordinator
Sep 23, 2015 at 3:49 PM
we add an
 Assembly.GetLinkerTimestamp().GetHashCode()
onto the end of our script and css registrations so a new build of a website ensures you will pull fresh js and css.
Ok so maybe that hasn't changed since the last release but the site as a whole has....