W3 Total Cache
Query String ID for Javascript/Stylesheet Caching (3 posts)

  1. Jesse Gardner
    Posted 3 years ago #

    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


  2. Jesse Gardner
    Posted 3 years ago #

    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.

  3. Jesse Gardner
    Posted 3 years ago #

    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

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • W3 Total Cache
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.