Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Can you force browser to find updated graphic?
Old 11-06-2008, 04:57 PM Can you force browser to find updated graphic?
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
Hello. I have an image that will be present on many pages but will change from week to week. I would like to be able to just swap the image file each week while keeping the same file path to save updating time.

Obviously, upon the user revisiting the page, the original cached image will display since it has the same path name. Is there a way to avoid this?

Perhaps a javascript image swap that gets run at the end of the page to simply force a re-load of the image?
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
 
Register now for full access!
Old 11-06-2008, 07:01 PM Re: Can you force browser to find updated graphic?
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I don't believe there's an absolute way to force clearing the cache, but there do seem to be some solutions.

One is to add

<meta http-equiv="pragma" content="no-cache" />

in the head section of your page. I'm not sure if all browsers honor it. I don't think it will work in all of them.

Another option I found while searching is to add a random number to the end of the src.

src="your-image.jpg?state=random-number"

You can use whatever you want to generate the random number, but a suggestion would be to use a JavaScript Date Object. Since the date will always be changing, the browser will consider the image file to be new every time someone loads the page, though it should still grab the right image.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 11-06-2008, 08:55 PM Re: Can you force browser to find updated graphic?
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
Thanks V, I'll try that. I figured there might be some javascript way to do it. I was at first thinking I'd manipulate the "title" text to change automatically in some way (like you mentioned) so it looked like new code to the browser but had the same file path to the image, but I wouldn't have thought of using your date object idea plus I wasn't sure if changing the title would have any influence on which image was loaded.

I was worried about the clear cache because of return users having to reload graphics for the whole page every time.

I'll try your idea. Thanks much!!

Duh! As I am writing this, I realize maybe I should just have that image in its own div and then I only change the background-image once in the css of THAT div every week!
Or is css page cached like other items?
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 11-07-2008, 02:54 PM Re: Can you force browser to find updated graphic?
aldor's Avatar
Ultra Talker

Posts: 479
Name: Alan
Location: Lincoln(UK)
Trades: 0
Surely if you use a different file name and put this in an include file all your problems are solved.
aldor is offline
Reply With Quote
View Public Profile
 
Old 11-07-2008, 08:19 PM Re: Can you force browser to find updated graphic?
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
The css file will be cached too so you'd have the same issue. Adding some parameter on the end based on the date/time will probably work best to force the image to be loaded on every page refresh.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 11-08-2008, 10:31 AM Re: Can you force browser to find updated graphic?
racer x's Avatar
Ultra Talker

Posts: 457
Name: Randy
Location: Northern Wisconsin
Trades: 0
If something changes within the css file (like a new image name for my div) doesn't it have to reload the css page? I read somewhere that most browsers will check the date on which a page was last updated, if the page has a more recent date than the one in cache, it will load the current one.

I can't seem to find a clear answer.
Does the browser look at a page and then match it line-for-line to the one in its' cache to determine if it has been updated?
OR
Does the browser check for the date the page was last updated?
OR
Does the browser only pay attention to the changed lines(thus loading new content) and call on the cache for the rest of the page? (e.g. It displays updated text on home page but uses the images in cache if the file paths match, etc.)
racer x is offline
Reply With Quote
View Public Profile Visit racer x's homepage!
 
Old 11-11-2008, 08:56 PM Re: Can you force browser to find updated graphic?
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I think some of it depends on how you have your browser set. You can usually have it check for new pages under several circumstances.

If I'm not mistaken when the browser is checking to see if there's a new version of the page it will look at the html. Assuming your css is external the html link won't have changed. I don't think the browser goes looking for the line by line code in the css file, though I could be wrong. Sooner or later it will, but I'm not sure if it will check at the same time it's checking the html.

While working on a site I've noticed that most of the time it does use the newest css, but other times I seem to have to refresh a couple times before the new css is there.

I guess I'm not really sure what the answer to your question is. Hopefully someone behind us will know. Otherwise it will make for some interesting research.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 11-17-2008, 03:42 PM Re: Can you force browser to find updated graphic?
deejne's Avatar
Novice Talker

Posts: 14
Name: DJN
Trades: 0
Quote:
Originally Posted by vangogh View Post
I don't believe there's an absolute way to force clearing the cache, but there do seem to be some solutions.

One is to add

<meta http-equiv="pragma" content="no-cache" />

in the head section of your page. I'm not sure if all browsers honor it. I don't think it will work in all of them.

Another option I found while searching is to add a random number to the end of the src.

src="your-image.jpg?state=random-number"

You can use whatever you want to generate the random number, but a suggestion would be to use a JavaScript Date Object. Since the date will always be changing, the browser will consider the image file to be new every time someone loads the page, though it should still grab the right image.
yeah should be good on this
__________________
E. deejne (at) gmail.com - AIM. deej4vendetta - ICQ. 382100572
deejne is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Can you force browser to find updated graphic?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.91998 seconds with 12 queries