SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript version numbers

    I believe appending a version number to a JS file allows me to change that version number to guarantee a user isn't viewing an old, cached version of the file.

    But what is best?

    (1) js-file.js?v=4

    (2) js-file_v4.js

    Obviously (2) needs the filename changing, but looking at it, does (1) work? I'm 100% that (2) would work.

    Are there any other downfalls of either of the methods? What do other people use?

    I need to be 100% certain that changing the version number will ensure nobody gets an old file.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Both would work. Both would achieve the same thing. Pick the one you like best.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,176
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    This is a handy way to automate it:

    http://css-tricks.com/can-we-prevent-css-caching/

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Another commonly used way now is to use a build system, so that all of your related files are packaged up in to just the one file.

    For example, RequireJS has an optimizer that combines and minifies them in to just the one file, which can have its time/date in the filename.
    There are other ones for doing such a job too, which are mostly well covered in this blog post http://robertnyman.com/2010/01/19/to...-environments/
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •