My webpage won't update unless I hit the refresh button.
November 6, 2011 1:25 AM   Subscribe

Not exactly sure how to phrase this question, cause I don't know the lingo, but here goes. How do I make it so a browser automatically updates my web-page.

I have a web page that I've made using basic html and css on notepad. It's nothing fancy.

Now, recently I've updated some of the content. For example, the page used to say "we sell 1, 2, and 3." After I updated the page (uploading the files at HostGator), it should say "we sell 1, 2, 3 and 4."

However, when I type the page into my browser, it still says "we sell 1, 2, and 3." If I hit the refresh button, though, the page changes to the updated "we sell 1, 2, 3, and 4."

What html do I need to add so that browsers automatically refresh the page, so that I don't have folks checking back to the page looking for updates and not finding them cause their browser is just loading from memory?

Does this make sense?
posted by snwod to Computers & Internet (7 answers total) 1 user marked this as a favorite
 
Best answer: Strictly speaking, a refresh is considered "best practice" to tell the browser that there's something new there. If a completely new user loaded up the page in question after you posted an update, it's likely they'd receive the newest version of the site, so you're the only one this affects adversely, because your browser thinks that it has the most recent version.

You can set a "no-cache" option to tell the browser to not even try to cache the page. This will stop the browser from assuming that a cached version X seconds old does not need an update, and force load it from the server every time. More on that here.

But to answer your core question: it's unlikely your users are viewing the old version of the site. It's much more likely this is local to your experience since you're trying to fetch a new version of the site immediately after posting your changes.

Depending on your hosting environment, the host may cache as well, so that changes take a few seconds to come down the pipe and show up for you. This doesn't sound likely if a force-refresh triggers an immediate update every single time, but it's something else to consider.

Finally, you can make sure that your server's clock is set correctly, and that your computer's clock is set correctly. Correct time is important in determining whether to look for a new version, or if your cache is likely the latest. If your browser has a cached version from the future, this can confuse things. (The server reports the last modified time of the file to be behind the current time on your computer's cached copy.)

Next time you update, load the site directly from a separate computer or from your phone and see if it shows the update immediately or if you have to hit refresh first. I'm guessing it will load just fine.
posted by disillusioned at 1:45 AM on November 6, 2011 [3 favorites]


Best answer: What you want to do is tell the browser not to put your content in it's cache.

You can do that by adding the following code to the <HEAD> section of your page:

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

posted by crunchland at 1:49 AM on November 6, 2011 [2 favorites]


disillusioned and crunchland are both right. This really isn't an issue for a variety of reason, the main one being that people simply hit the reload button and get the latest copy of your page. Secondly, your browser has fairly sane caching preferences so even if someone visits your site multiple times a day, they will get the latest version.

You might still, however, need to inform your visitors about new stuff on your site. This isn't related to caching but the fact that depending on the size of your site, visitors might miss newly added stuff even if they see the latest version of your page. This also applies to single page web sites that are very long and information rich: you need a section at the top of the page that informs visitors that stuff has been changed.
posted by Foci for Analysis at 3:49 AM on November 6, 2011 [1 favorite]


I don't think this is what you want, but if this page is getting very frequently updated (like every few minutes), you can force a refresh every X seconds. However, that's a practice that should be reserved for news sites, stock sites, places that really have a need to show the absolute latest page to every user. Otherwise it's irritating and wastes everybody's bandwidth. Also, if you have customers using slow connections, and you have your page update every minute, it might not even finish loading before it tries to refresh.

HTTP is fundamentally a "pull" protocol; browsers (clients) send requests to a server and get back answers. There's no provision for the server to contact a client. In other words, when you upload a new version on your server, the client has no idea, in fact no conceivable way of knowing that you have done so. It's like Barnes and Noble puts a new edition of your favorite book on the shelf, but of course the copy you have at home doesn't change. You would have to go get it yourself.

Sophisticated web pages (think Facebook chat, e.g.) appear to get updates sent from the server, but that's an illusion. In reality, the client is sending a request for new content every 2 seconds, the equivalent of saying "Can you hear me now? Can you hear me now? Can you hear me now?" until the other party on the call says, "Yes, and here's what's new." However, that method pretty much requires a Javascript library for that purpose (unless you're a Javascript/XML god/goddess), and is probably overkill.
posted by wnissen at 7:07 AM on November 6, 2011


This sounds like the fault of your browser. A web server usually won't have two copies of the same file - people who visit anew won't see an older version. There are some conditions where sites are behind a load balancer where it's possible, but on a shared host, extremely, incredibly unlikely.

Have you tried:
- closing your browser entirely between visits?
- clearing your browser cache (Hey, nice work Indiana University for maintaining instructions)

You may also see if you have something wonky on your server, if your page is putting out timestamps that are very incorrect it's possible that your browser will think what's coming off the server is expired when it's really not. This would be something you'd have to take up with your hosting company.

Now, if you were having to re-upload the file again and again to see the changes, I'd advise this thing I've done when dealing with flaky hosts. Visit the url in the browser, DELETE the file for the url, REVISIT the url in a browser (which will give you an error), the REUPLOAD the file, and REVISIT again. If a web server has an aggressive cache mechanism this can overcome that.
posted by artlung at 9:40 AM on November 6, 2011


If you want to see the latest version of your site after you've uploaded files, you can force a hard refresh and bypass your cache by hitting CTRL + F5 (or maybe even holding CTRL and clicking the refresh button). But yeah, this probably isn't an issue for your customers.
posted by jng at 11:59 AM on November 6, 2011


Response by poster: Thanks for the info, guys. It seems to have worked!
posted by snwod at 2:18 AM on November 7, 2011


« Older Aptitude-based hiring and on-the-job hiring in...   |   How to install gcc 4.2 on a macbook with Xcode 4.2 Newer »
This thread is closed to new comments.