SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Strokin' Morango dele454's Avatar
    Join Date
    Oct 2005
    Location
    Cape town, South Africa
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Out of curiosity...

    I like to know why some designers include parameters in their path to files like the example below:

    Code:
    <head>
    <script src="/javascripts/effects.js?1219948479" type="text/javascript"></script>
    
    <script src="/javascripts/dragdrop.js?1219948479" type="text/javascript"></script>
    <script src="/javascripts/controls.js?1219948479" type="text/javascript"></script>
    <script src="/javascripts/application.js?1219948479" type="text/javascript"></script>
    </head>
    Why do that? i see a lot of these in stylesheet declaration and js. Does anyone know?


    Thanks

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It might be to prevent the problem of caching...
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As Jimmy said, it's usually done to prevent caching, by people who don't understand caching and HTTP cache control headers.

    By appending a random parameter (often the current timestamp in Unix epoch format), each request seems unique to the browser, preventing it from using a cached version.
    Birnam wood is come to Dunsinane

  4. #4
    Strokin' Morango dele454's Avatar
    Join Date
    Oct 2005
    Location
    Cape town, South Africa
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    As Jimmy said, it's usually done to prevent caching, by people who don't understand caching and HTTP cache control headers.
    ??

    What do you mean by people who dont understand caching. Can you clarify what you mean?

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    By setting the control headers to tell the browser not to cache files that you don't want cached you can control caching properly without needing to add random numbers to simulate the same effect.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dele454 View Post
    What do you mean by people who dont understand caching. Can you clarify what you mean?
    Many designers seem to view caching as something evil: something browsers do just to spite them. In fact, caching is a very useful mechanism that speeds up the user experience as well as saves on server bandwidth.

    One of the advantages of using external CSS and JavaScript files is that browsers can cache them and don't have to request them every time a page is loaded.

    Using the method in the OP, you're effectively (but not efficaciously) preventing these files from being cached. It takes longer to load each page, because the browser needlessly has to retrieve the same files over and over again, and the server uses a lot more bandwidth than it should have to.

    The reason for doing this is that the designer or developer makes changes in the style sheet or script file and want those to take effect as soon as possible. In my opinion, the best way of achieving that is to change the file name (although using a query parameter may be an alternative, but it should only change if the file's content has changed). Some user agents may choose not to cache any resource with a query parameter in its URI, though.

    Most of the time it's best to simply use the correct HTTP cache control headers. Make the file 'expire' in 1 hour or 24 hours or whatever seems appropriate, and tell user agents that they 'must revalidate', i.e., check each time if there's a newer version available.
    Birnam wood is come to Dunsinane

  7. #7
    Strokin' Morango dele454's Avatar
    Join Date
    Oct 2005
    Location
    Cape town, South Africa
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    By setting the control headers to tell the browser not to cache files that you don't want cached you can control caching properly without needing to add random numbers to simulate the same effect.
    Thanks am seeing clearly now


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
  •