Title: Query String ID for Javascript/Stylesheet Caching
Last modified: August 20, 2016

---

# Query String ID for Javascript/Stylesheet Caching

 *  [Jesse Gardner](https://wordpress.org/support/users/plasticmind/)
 * (@plasticmind)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/query-string-id-for-javascriptstylesheet-caching/)
 * Hey Fredrick,
 * In noticed that in /lib/W3/Plugin/BrowserCache.php you’re generating the $cache_id
   by creating an MD5 hash of all the options that are set. It’s this variable that’s
   used to append to javascript and stylesheet calls (e.g. `styles.css?fdb553`).
   Practically speaking, a user has to change some of the W3TC options in order 
   to have a new query string generated.
 * Have you ever considered creating the $cache_id with an MD5 hash of the included
   file (e.g. `md5_file($file)`) instead? That way any time the stylesheet or javascript
   changes, the browser (and/or CDN) is forced to pick up the change?
 * Related question: [http://wordpress.org/support/topic/refresh-query-string-for-assets](http://wordpress.org/support/topic/refresh-query-string-for-assets)
 * [http://wordpress.org/extend/plugins/w3-total-cache/](http://wordpress.org/extend/plugins/w3-total-cache/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Jesse Gardner](https://wordpress.org/support/users/plasticmind/)
 * (@plasticmind)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/query-string-id-for-javascriptstylesheet-caching/#post-3271149)
 * After thinking about it for a bit, perhaps a combination of the two might work
   best.
 * I’m thinking that if you appended the linked files with an MD5 hash of the W3TC
   options **and** and MD5 hash of the linked file size, you’d force browsers to
   download the new file when the options change or when the file changes. Seems
   like a win-win to me.
 *  Thread Starter [Jesse Gardner](https://wordpress.org/support/users/plasticmind/)
 * (@plasticmind)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/query-string-id-for-javascriptstylesheet-caching/#post-3271248)
 * For what it’s worth, here’s how I solved this.
 * First, I disabled the W3TC option to add query strings to the tail of JS/CSS 
   files.
 * Then, I dropped the following code into my functions.php, specifically where 
   I’m registering my main stylesheet and javascript files: [https://gist.github.com/4282236](https://gist.github.com/4282236)
 * Nutshell: when registering m primary stylesheet and javascript, instead of passing
   a version number, I’m passing a CRC32-hashed string of the file. That way, when
   the size of the file changes (i.e. you make an update), so does this hash string.
 * Thus, browsers and proxies are forced to download the updated file, no matter
   the caching policy.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Query String ID for Javascript/Stylesheet Caching’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

 * 2 replies
 * 1 participant
 * Last reply from: [Jesse Gardner](https://wordpress.org/support/users/plasticmind/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/query-string-id-for-javascriptstylesheet-caching/#post-3271248)
 * Status: not resolved