Results 1 to 2 of 2

Thread: Handling the Cache problem

  1. #1
    Join Date
    Sep 2006

    Question Handling the Cache problem


    As you know applications like gmail / yahoomail they constantly keep changing their js/css and when you login you dont have to clear your browser cache to see the new changes, they are automatically shown to you.

    How do they do this? I see there are two approaches:

    1) in your code where you specify the path of the js/css you append time with a querystring that will force your browser to load the lastest js/css no matter it has been modified or not.

    2) You use the "Pragma: No-cache" Tag in your page.

    But the problem in these approaches is that your application makes an HTTP request every time its called since it assumes the file is new.

    So whats the solution?

    Any help is appreciated.

  2. #2
    Join Date
    Aug 2004
    Don't know how they do it, but I just thought of this: have the main app get the last mod time of the file in question, and use that as a (unused) query string value.
    PHP Code:
    $jsFileUrl $jsFile "?v=" file_mtime($_SERVER['DOCUMENT_ROOT'] . $jsFile);
    <script type='text/javascript' src='<?php echo $jsFileUrl?>'></script>
    This way the browser could cache it until the resource file is changed and gets a new mod time.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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