4 Replies Latest reply on Jul 31, 2008 9:48 AM by Rudei

    How to automatically reload .js file

    Rudei Level 1
      Hi,

      I have a HTML page on that includes a .js file. On changing the .js file, I sometimes need to CTRL+F5 in order to get the new contents of the .js file included on the page and the normal F5 doesn't work.

      Is this normal or is there something I can add to automate this load? We want customers to see the new contents and not the old .js contents.

      Thanks

      R.
        • 1. Re: How to automatically reload .js file
          Level 7
          .oO(Rudei)

          > I have a HTML page on that includes a .js file. On changing the .js file, I
          >sometimes need to CTRL+F5 in order to get the new contents of the .js file
          >included on the page and the normal F5 doesn't work.
          >
          > Is this normal

          Yes. This may happen with all cacheable resources: JS, CSS, images,
          static HTML pages ...

          >or is there something I can add to automate this load? We want
          >customers to see the new contents and not the old .js contents.

          They will see it, either immediately or after a few hours, dependent on
          the browser configuration. Usually cached resources will be checked
          again automatically after a while to see if they are still fresh or if
          they were modified on the server.

          There are also ways to control the caching behaviour with HTTP headers,
          but this requires some modifications in the server configuration, for
          example in an .htaccess file.

          http://www.mnot.net/cache_docs/
          http://www.mnot.net/cacheability/
          http://www.askapache.com/htaccess/apache-speed-cache-control.html

          Micha
          • 2. Re: How to automatically reload .js file
            Rudei Level 1
            Thanks Michael,

            So if I set "expires" within the .htacess to say 1 month from now(we have monthly updates), as long as the web server date is correct the cache will be refreshed every month?
            • 3. Re: How to automatically reload .js file
              Level 7
              .oO(Rudei)

              >So if I set "expires" within the .htacess to say 1 month from now(we
              >have monthly updates), as long as the web server date is correct the
              >cache will be refreshed every month?

              That's how it should be. In this case you explicitly tell the browsers
              (and other clients) that the received resource should be considered
              fresh for the next month, so there's no need for the browser to check
              back with the server earlier. It will always serve the resource directly
              from its own cache, unless you force a reload with ctrl-F5 or clear the
              cache (dependent on their configuration some browsers might still
              contact the server even if the expiration date is not reached yet).

              But using an Expires header is just one of the various ways to control
              caching.

              Micha
              • 4. Re: How to automatically reload .js file
                Rudei Level 1
                I added into my .htaccess:

                Expires: Fri, 30 Oct 1998 14:19:41 GMT

                and got this message:

                Internal Server Error
                The server encountered an internal error or misconfiguration and was unable to complete your request.

                Please contact the server administrator, webmaster@test.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

                More information about this error may be available in the server error log.

                Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

                What have I done wrong? I thought all accesses would be refreshed and not use the cache?