Reputation: 43
I have a problem with cache busting after minifying my js files via uglify using method from here: http://symfony.com/doc/current/cookbook/assetic/uglifyjs.html
After minifying my files are loaded as 1f4daf9.js
without assets version which is set in the config.
My uglify filter is configured like this:
filters:
uglifyjs2:
bin: /usr/local/bin/uglifyjs
And what I want to achive is to get 1f4daf9.js?r1234
name with assets version so the browser is forced to reload it. So how can I do that?
Upvotes: 0
Views: 706
Reputation: 43
Found answer on https://stackoverflow.com/a/27900224/3922926
You actually need to use {{ asset(asset_url) }} instead of {{ asset_url }} since it doesn't add version to asset_url automatically.
Upvotes: 2
Reputation: 35139
If you set an output filename to a fixed filename on disk, you can then arrange the cache-busting to be done on the request URL (which isn't actually named identically). It would still send the original file from disk however. The h5bp cache-busting config has an example:
# If you're not using a build process to manage your filename version
# revving, you might want to consider enabling the following directives
# to route all requests such as `/style.12345.css` to `/style.css`.
#
# To understand why this is important and even a better solution than
# using something like `*.css?v231`, please see:
# http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L]
</IfModule>
Unfortunately, the assets_version_format
can't embed strings within the filename, which would leave the file-naming as a somewhat manual process.
This will work for Javascript as equally as CSS. The JS and CSS files would then also be able to be set with long-expiry times, meaning they will be cached by the viewing browser, and not re-requested at all - until the URL (with the embedded version, or hash) changes, and the latest version is fetched.
Upvotes: 0