Web Analytics Made Easy -
StatCounter How to force a page reload? - CodingForum

Announcement

Collapse
No announcement yet.

How to force a page reload?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to force a page reload?

    I have a webpage that is just written in html and javascript. Its a gallery based website, and I often change the images. People often remark that they are not always seeing the newest images. I believe this is just a browser setting issue, as their browser may just be referencing a page from recent history rather than downloading a new one. I would instead, like the page to auto-fresh when someone connects to the page so that they are always seeing the latest version of the page, without them having to manually refresh.

    What would be the best way to do this?

  • #2
    Yea it's probably just cached images. Instead of reloading the page, which might not accomplish anything you want, add a random variable to the end of your image files.

    <img src="image.jpg?q=<YOUR_RANDOM_STRING_HERE>" />
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

    Comment


    • #3
      The best way to handle version control is using the expires headers rather than trying to fake it with a querystring.
      Stephen
      Learn Modern JavaScript - http://javascriptexample.net/
      Helping others to solve their computer problem at http://www.felgall.com/

      Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

      Comment


      • #4
        Originally posted by helpneeded22 View Post
        I have a webpage that is just written in html and javascript. Its a gallery based website, and I often change the images. People often remark that they are not always seeing the newest images. I believe this is just a browser setting issue, as their browser may just be referencing a page from recent history rather than downloading a new one. I would instead, like the page to auto-fresh when someone connects to the page so that they are always seeing the latest version of the page, without them having to manually refresh.

        What would be the best way to do this?
        The proper solution is to output a cache-control: no-cache HTTP header for all files that you expect to change. Contrary to the name, the header doesn't prevent caching, but forces the browser to check for a new version of files on every page load instead of lazy-loading files without consulting the server. Only if there is no newer file will a cached version be used.

        I was just experiencing this issue with stylesheets and ended up setting cache-control: no-cache site-wide by default, then disabling it for certain folders like those containing fonts or image files with version numbers in the filename since those will never change.

        If you know the date/time each image will change, you can also use the expires HTTP header solution mentioned by felgall. The main issue with that is that you need to consistently update the expiration date, otherwise the date will pass and your content will end up perpetually expired, breaking caching.

        Comment

        Working...
        X