Can I force the client to stop caching old stylesheets and javascript?

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

    Can I force the client to stop caching old stylesheets and javascript?

    Can I force the client to stop caching old stylesheets and javascript?

    In my dynamic web-site, I need to force the client to stop caching old
    versions of my stylesheets and javascript. Can I do this by including
    a querystring with the url with each external stylesheet and script
    file declaration?

    For example:

    <link type="text/css" rel="stylesheet " href="../images/menu.css?
    v=1" />
    <script type="text/javascript" src="../javascript/menu.js?v=1"></
    script>

    This is far easier, for me, than coding the web-server to change the
    file headers. I just want confirmation that this will work. It seems
    obvious that it should but I'm curious as to why I've never come
    across this technique before.

  • Rik Wasmus

    #2
    Re: Can I force the client to stop caching old stylesheets and javascript?

    On Tue, 16 Oct 2007 15:50:41 +0200, mark4asp <mark4asp@gmail .comwrote:
    Can I force the client to stop caching old stylesheets and javascript?
    >
    In my dynamic web-site, I need to force the client to stop caching old
    versions of my stylesheets and javascript. Can I do this by including
    a querystring with the url with each external stylesheet and script
    file declaration?
    >
    For example:
    >
    <link type="text/css" rel="stylesheet " href="../images/menu.css?
    v=1" />
    <script type="text/javascript" src="../javascript/menu.js?v=1"></
    script>
    >
    This is far easier, for me, than coding the web-server to change the
    file headers.
    Shouldn't be...
    I just want confirmation that this will work. It seems
    obvious that it should but I'm curious as to why I've never come
    across this technique before.
    It works (well, as long as you keep changing the query string), and is
    widely in use.
    --
    Rik Wasmus

    Comment

    • André Gillibert

      #3
      Re: Can I force the client to stop caching old stylesheets and javascript?

      mark4asp wrote:
      Can I force the client to stop caching old stylesheets and javascript?
      >
      In my dynamic web-site, I need to force the client to stop caching old
      versions of my stylesheets and javascript. Can I do this by including
      a querystring with the url with each external stylesheet and script
      file declaration?
      Yes, but that's evil. Fortunately, you may be punished by a low google
      rank! Crawlers assume that a URI uniquely identifies a resource.

      Use the HTTP headers (e.g. set expiration to zero second). If the page is
      generated by a script or contains SSI, your server should use the correct
      headers by default.
      If the page is static, then, why preventing caching? To improve the page
      hits statistics? That would be stupid and evil.
      What is it for?

      I just want confirmation that this will work.
      It will work as using pseudonyms to commit evil deeds reduces the chance
      of being identified.
      It seems obvious that it should but I'm curious as to why I've never come
      across this technique before.
      >
      Because, modifying HTTP headers is much nicer, much more civilized, and
      much more natural. It's the direct, obvious, fine, standardized way to
      control caching. Your way, is worse than failure:



      --
      If you've a question that doesn't belong to Usenet, contact me at
      <tabkanDELETETH ISnaz@yahoDELET ETHATo.fr>

      Comment

      Working...