Grow your CSS skills. Land your dream job.

auto-versioning filenames for cache busting

  • # January 23, 2013 at 1:26 pm

    I’m a bit behind the ball on this. I have not used far-future Expires headers for cache control.

    Main reason, I’m not sure on best-practices of doing this with the least amount of effort.

    I’ve read [this article](http://derek.io/blog/2009/auto-versioning-javascript-and-css-files/ “this article”), but I’m not sure if this is the easiest way or the best way to do so.

    Anyone have any insight to share?

    # January 23, 2013 at 1:37 pm

    Usually you’d just have one header file that you include on every page, so the easiest way I think would just be to add a query string every time you change the file. The browser will see it as a different file.

    # January 23, 2013 at 1:47 pm

    I’ve seen the query string idea, but the article linked explain why it is not a good idea to do so. Scroll to the bottom and read the end of the article.

    # January 23, 2013 at 1:48 pm

    BTW, cool blog you have. I hope you continue to write more articles!

    # January 23, 2013 at 3:00 pm

    Servers *should* (and almost always *do*, in my experience) take a query string into consideration when deciding whether to use cached pages.

    # January 23, 2013 at 3:06 pm

    So is this the way you guys are going about it?
    To append to the query string, are you utilizing a PHP function, or manually changing the query string value?

    # January 23, 2013 at 5:04 pm

    Sorry about that. Had a quick look at the article, saw it was doing all sorts of fancy server-side stuff, and didn’t scroll down all the way.

    I would just change the query string manually. It’s unlikely that you would be liking up the same stylesheet/js file from lots of different files.

    # January 23, 2013 at 7:44 pm

    > So is this the way you guys are going about it? To append to the query string, are you utilizing a PHP function, or manually changing the query string value?

    I usually append `?< ?php echo time(); ?>`. I’ll admit that’s lazy of me, but it works. A better approach is to set the appropriate headers.

    If you’re only “basting the cache” once (e.g., you updated whatever, and you don’t plan on doing so again anytime soon) you might add the query string manually.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".