JS File Caching

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Attila

    JS File Caching

    Hello,

    My website stores JavaScript in .js files. From what I understand,
    most web browsers cache .js files. My question is, if I make changes
    to the file, how can I be sure that users will use the most recent
    version of the JS file?

    Thanks,
    Attila
  • Michael Winter

    #2
    Re: JS File Caching

    On 16 Jan 2004 07:33:19 -0800, Attila <ThisIsAFakeAdd ress35@hotmail. com>
    wrote:
    [color=blue]
    > My website stores JavaScript in .js files. From what I understand,
    > most web browsers cache .js files. My question is, if I make changes
    > to the file, how can I be sure that users will use the most recent
    > version of the JS file?[/color]

    Cache management with .js files (any file, really) should work the same as
    it does with .htm(l) files. If it doesn't you have a bad browser.

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Dr John Stockton

      #3
      Re: JS File Caching

      JRS: In article <9516751f.04011 60733.4da55fb@p osting.google.c om>, seen
      in news:comp.lang. javascript, Attila <ThisIsAFakeAdd ress35@hotmail. com>
      posted at Fri, 16 Jan 2004 07:33:19 :-
      [color=blue]
      > My website stores JavaScript in .js files. From what I understand,
      >most web browsers cache .js files. My question is, if I make changes
      >to the file, how can I be sure that users will use the most recent
      >version of the JS file?[/color]

      Untested :

      every page has

      <script type="text/javascript">

      document.write(
      '<script type="text/javascript" src="version.js ?' +
      new Date() + '"></scr'+'ipt>'
      )

      </script>

      version.js is thus effectively uncached.

      File version.js contains ONLY

      var LatestVersion = 99 // update number as needed


      Other pages contain, after as above,

      <script type="text/javascript">

      document.write(
      '<script type="text/javascript" src="page45.js? ' +
      LatestVersion + '"></scr'+'ipt>'
      )

      </script>


      ISTR that script can write script blocks, but the </script> must be
      concealed.

      Now, changing the contents of version.js effectively invalidates all
      caches, although it does not flush the old stuff. ???

      Naturally, you can have an array for LatestVersion, to control cacheing
      of different groups of pages independently.

      /Untested.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      Working...