Filename cache busting for WordPress styles and scripts
To embed custom CSS styles and scripts in WordPress you should use the wp_enqueue_script()
, wp_enqueue_style()
, wp_register_script()
and/or wp_register_style()
functions. Each of these functions allows you to define a version. By default it’s the version of WordPress. The version identifier will be in the URL to the script as a query string.
The version identifier is used to expire the URL. Since the browser detects the new URL as a new resource, it will use the new instead of the cached resource.
Sadly not all endpoints respect the query string. From Google Developers:
Most proxies, most notably Squid up through version 3.0, do not cache resources with a “?” in their URL even if a
Cache-control: public header
is present in the response. To enable proxy caching for these resources, remove query strings from references to static resources, and instead encode the parameters into the file names themselves.
So the goal is to encode the version identifier into the filename without renaming the resource on the filesystem. This is where the following plugin comes in.
Continue reading …