skeeks-semenov / yii2-assets-auto-compress

Automatic compilation of js + css + html
https://skeeks.com/
BSD 3-Clause "New" or "Revised" License
157 stars 43 forks source link

CSS and JS caching is defeated by URL parameters #28

Open meyergru opened 7 years ago

meyergru commented 7 years ago

I found that because the compressed resources are suffixed by a '?v=' parameter that has the file creation time, effectively resource caching is defeated.

Why is this? The name of the file is already made of the MD5 of the file content, so why is there another parameter which is not really used anyway? I assume you tried to defeat the resource caching if the file was modified, but in that case, the MD5 would differ anyway. By adding an URL parameter, nothing gets cached at all.

If I am correct, it would suffice to just remove the code lines where the '?v=' is added.

skeeks-semenov commented 7 years ago

Yes, this is done to clear the cache. And it need not be removed.

The logic is that under any scenario, checked md5 just from a set of files. If a single file is updated, the yii2 change it ?v=value and then md5 of the data set in the same change. This is easy to do and does not require the reading of all the files and comparing them md5 values.

https://github.com/skeeks-semenov/yii2-assets-auto-compress/blob/master/AssetsAutoCompressComponent.php#L353

meyergru commented 7 years ago

Excuse me, my bad: I was wrong. Firefox did never cache the resources because of an obscure Apache bug with mod_deflate and mod_brotli explained here:

https://fullstackhack.wordpress.com/2014/12/10/the-pain-of-etags-mod_deflate-apache-2-4-and-tomcat-7/