The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> [Q]Question about browser Image Caching, Quite confused about some browser image caching with my site, please h
CompactTortoise
post Jun 27 2011, 08:19 PM
Post #1





Group: Members
Posts: 2
Joined: 27-June 11
Member No.: 14,845



I'm creating my own ajax/php web chat client and as i'm planning to go mobile and im running my own home server i'm trying to limit the amount of data sent.

To do this i process the conversations and only send the new messages (good place to start tongue.gif) but now im adding my own little Emoticons to it.

Now my question with a little explanation

I have a page, this page is called Chat.php. When this page first loads the browser will load all the emoticon images in a DIV tag to the right.
Another div tag is set up to display the conversation.

every half a second the page/client will check for new messages (javascript http request), if there are new messages the 'getconvo.php' page will echo the messages and the client will run the http response code. This appends the messages to the end of the DIV tag that shows the convo.

Now if one of those messages contains my <img /> code for an emoticon thats already displayed on the page. will it request it again from the server or use a cached version of the image? The Convo.php page is never refreshed. just has new code appended from the httpResponse.

Is there a way i can check? and if the browser does keep requesting the image is there a way i can force cache images? I'm using PHP and Javascript so either way is fine =)

Thanks in advance

CompactTortoise.

This post has been edited by CompactTortoise: Jun 27 2011, 08:21 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jun 28 2011, 04:28 AM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



I'm on thin ice here, but I think that if you use a "HTTP header viewer plugin" (I just invented that term - yay me!) for your browser you should be able to find something useful out from the conversation between the browser and the server.

For example, if I reload a page a lot of files get 304 Not Modified, which should mean the file can be taken from cache. Problem is I'm not sure if a some cache headers must be set for a 304 to be sent in the first place.

Anyway, maybe it's a starting point.
För IE there are ieHTTPHeaders which is free and HttpWatch which is more elegant but alas far from free.
http://www.blunck.info/iehttpheaders.html
http://www.httpwatch.com/

I'm sure there are more, both for IE and other browsers, but off the cuff, that's what I've got.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jun 28 2011, 04:30 AM
Post #3


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Come to think of it, the same information should be in your access log, if your host gives you access to it and the server is configured to save detailed enough information.

I'm getting confused now. Better get out in the sun again.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CompactTortoise
post Jun 28 2011, 08:37 AM
Post #4





Group: Members
Posts: 2
Joined: 27-June 11
Member No.: 14,845



QUOTE(pandy @ Jun 28 2011, 10:30 AM) *

Come to think of it, the same information should be in your access log, if your host gives you access to it and the server is configured to save detailed enough information.

I'm getting confused now. Better get out in the sun again.


I've checked the access log and it appears to have only sent the images once ("GET /chat/img/emotes/smile.png HTTP/1.1" 304 ) I take it that line is how the browser checks if an image has been updated?

If so will the browser only get the images once the server says theres a new one?

Thanks alot for the help

CompactTortoise
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jun 28 2011, 09:00 AM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



I *think* so, but I'm pretty confused about caching myself. I suspect Darin is the one with the definitive answer.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 28 2011, 09:29 AM
Post #6


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(CompactTortoise @ Jun 28 2011, 03:19 AM) *
When this page first loads the browser will load all the emoticon images in a DIV tag to the right.
Another div tag is set up to display the conversation.

Since you use Ajax the whole web page is not reloaded. Maybe the browser uses the cached image file when new IMG elements are generated by Ajax/javascript (as opposed to when reloading the whole page)? unsure.gif

QUOTE
and if the browser does keep requesting the image is there a way i can force cache images?

Isn't this ultimately up to the browser and its settings? unsure.gif

See also http://htmlhelp.com/faq/html/publish.html#no-cache (though it's about the opposite problem).



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jun 28 2011, 09:52 AM
Post #7


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Yeah, you can turn caching off, but that isn't the issue here, rather if the image can be loaded from cache at all or if they are always downloaded again.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 28 2011, 01:39 PM
Post #8


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Jun 28 2011, 04:52 PM) *

rather if the image can be loaded from cache at all or if they are always downloaded again.

Isn't that up to the browser too? For example, MSIE and Opera let you choose to never check for new pages/images. Don't know about Firefox, does it have any cache settings?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jun 28 2011, 02:43 PM
Post #9


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



It isn't about that. The OP didn't know if cashing will occur with the method he uses and neither did I, but I thought so.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 28 2011, 05:17 PM
Post #10


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(Christian J @ Jun 28 2011, 04:29 PM) *

Maybe the browser uses the cached image file when new IMG elements are generated by Ajax/javascript (as opposed to when reloading the whole page)? unsure.gif

I made an experiment:

CODE
<img src="foo.jpg" onclick="document.body.innerHTML+='<hr><img src=\'foo.jpg\'>';">

First I loaded a web page containing the above static image (depicting a dog). Next I replaced the image file with another one also named foo.jpg (but depicting a cat). Finally I created a second identical IMG element using the javascript above. All browsers I tested with then displayed the dog image in both IMG elements, suggesting that the cached version was used for the second IMG (a browser requesting the image file again from the server should get the cat image). This also happened even when I set Opera11 to always check if images are updated on the server.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th March 2024 - 06:45 AM