refreshed script

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

    refreshed script

    Hi,

    Is there a way to force the browser to use the fresh script from the
    website instead of reading the cached .js file. I have the same
    question for the HTML code for that matter. Any meta tag, attribute,
    that will make the browser to get the updated page from the webserver
    instead of what was cached.

    TIA.
  • Randy Webb

    #2
    Re: refreshed script

    Aamir Ghanchi wrote:
    [color=blue]
    > Hi,
    >
    > Is there a way to force the browser to use the fresh script from the
    > website instead of reading the cached .js file.[/color]

    Yes. Assuming Javascript is enabled.

    I have the same question for the HTML code for that matter.

    Same answer.
    [color=blue]
    > Any meta tag, attribute, that will make the browser to get
    > the updated page from the webserver instead of what was cached.[/color]

    No, not with a meta tag.
    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Grant Wagner

      #3
      Re: refreshed script

      Aamir Ghanchi wrote:
      [color=blue]
      > Hi,
      >
      > Is there a way to force the browser to use the fresh script from the
      > website instead of reading the cached .js file. I have the same
      > question for the HTML code for that matter. Any meta tag, attribute,
      > that will make the browser to get the updated page from the webserver
      > instead of what was cached.[/color]

      Depending on how often your external JavaScript content changes, you can
      do one of two things:

      1) <script type="text/javascript"
      src="myfile.js? v=200407081320" ></script>

      Then simply modify the value of the [v]ersion when "myfile.js" changes.
      If you use "myfile.js" in multiple places, put the above code into
      another file and server-side #include it in the pages you need. When
      "myfile.js" changes, you upload it, modify the SSI that includes the
      above syntax and upload it.

      2) <script type="text/javascript">
      document.write(
      '<script type="text/javascript" src="myfile.js? v=' +
      (new Date()).getTime () +
      '><\/script>'
      );
      </script>

      (or you can use server-side code to do the same thing)

      This will result in "myfile.js" being downloaded with each visit to the
      page, which sort of negates the benefit of using an external JavaScript
      file.


      I use the first concept a lot, an external JS file with a SSI to include
      it on pages. It is the easiest to maintain and guarantees everyone gets a
      fresh copy only when I actually change something.

      You can also control caching behaviour from your server: <url:
      http://www.mnot.net/cache_docs/#CONTROL />

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq


      Comment

      Working...