PDA

View Full Version : Do style sheets always cause a hit?


NeilFawcett
3-11-05, 06:49 AM
If you link a style sheet into your document, does this always count as a hit?

There have been various opinions on taking some style sheets and moving them directly into the html page they were previously linked from. The idea of this is of course to reduce hits down, at the expense of a bit of bandwidth.


Now, can anyone confirm if this is actually a good move or not. ie: Where you have a link to a style sheet in an HTML document, will it always cause a hit to your website? ie: Or will caching prevent browsers from regularly "hitting" it?


*EDIT*
From some experiments, looking at apache logs on a test machine, I cannot see an access request for CSS files (unless you do a refresh on the browser). HOWEVER, I can see every image, and every javascript file included being accessed everytime!

Here's an example... First is a refresh, next two and just revisits back to the same page:-

[11/Mar/2005:10:56:39 +0000] "GET /style.css HTTP/1.1" 304 -
[11/Mar/2005:10:56:39 +0000] "GET /script.js HTTP/1.1" 404 296
[11/Mar/2005:10:56:39 +0000] "GET /mainlogo.jpg HTTP/1.1" 404 301
[11/Mar/2005:10:56:39 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:10:56:39 +0000] "GET /shared/bar_back.jpg HTTP/1.1" 404 308
[11/Mar/2005:10:56:39 +0000] "GET /main.html HTTP/1.1" 200 23744
[11/Mar/2005:10:56:39 +0000] "GET /shared/empty.gif HTTP/1.1" 304 -
[11/Mar/2005:10:56:39 +0000] "GET /shared/c-tl.gif HTTP/1.1" 304 -
[11/Mar/2005:10:56:39 +0000] "GET /shared/c-tr.gif HTTP/1.1" 304 -
[11/Mar/2005:10:56:39 +0000] "GET /cgi/poll/polls_image.gif HTTP/1.1" 304 -

[11/Mar/2005:10:57:06 +0000] "GET /script.js HTTP/1.1" 404 296
[11/Mar/2005:10:57:06 +0000] "GET /main.html HTTP/1.1" 200 23744
[11/Mar/2005:10:57:06 +0000] "GET /mainlogo.jpg HTTP/1.1" 404 301
[11/Mar/2005:10:57:06 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:10:57:06 +0000] "GET /shared/bar_back.jpg HTTP/1.1" 404 308

[11/Mar/2005:10:57:33 +0000] "GET /script.js HTTP/1.1" 404 296
[11/Mar/2005:10:57:33 +0000] "GET /main.html HTTP/1.1" 200 23744
[11/Mar/2005:10:57:33 +0000] "GET /mainlogo.jpg HTTP/1.1" 404 301
[11/Mar/2005:10:57:33 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:10:57:33 +0000] "GET /shared/bar_back.jpg HTTP/1.1" 404 308


This would surely imply:-
- Style sheets are better left linked - They will only be accessed (hit) first time.
- Somes images will cause a hit every time the page is shown. Why are some cached & others not??
- Every javascript will cause a hit every time the page is shown.

Croc Hunter
3-11-05, 07:07 AM
It does count as a hit as it's retrieving the css file. Caching plays no part as a request for a file is a request, it just loads faster as you already have a 'copy' in your cache. Just think of it as a single photo cut into a jigsaw puzzle, the more pieces the more hits.

NeilFawcett
3-11-05, 07:34 AM
But the logs would seem to disagree with you. Here are two logs of IE and Firefox doing the same thing. Doing a REFRESH on "main.html". Clicking to "page2", and then clicking to go back to "main.html". Note on the second visit to "main.html" what is asked for!

IE
[11/Mar/2005:11:22:18 +0000] "GET /style.css HTTP/1.1" 304 -
[11/Mar/2005:11:22:18 +0000] "GET /script.js HTTP/1.1" 404 296
[11/Mar/2005:11:22:18 +0000] "GET /mainlogo.jpg HTTP/1.1" 404 301
[11/Mar/2005:11:22:18 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:11:22:18 +0000] "GET /shared/bar_back.jpg HTTP/1.1" 404 308
[11/Mar/2005:11:22:18 +0000] "GET /main.html HTTP/1.1" 200 23745
[11/Mar/2005:11:22:18 +0000] "GET /shared/empty.gif HTTP/1.1" 304 -
[11/Mar/2005:11:22:18 +0000] "GET /shared/c-tl.gif HTTP/1.1" 304 -
[11/Mar/2005:11:22:18 +0000] "GET /shared/c-tr.gif HTTP/1.1" 304 -
[11/Mar/2005:11:22:18 +0000] "GET /cgi/poll/polls_image.gif HTTP/1.1" 304 -

[11/Mar/2005:11:22:22 +0000] "GET /page2.html HTTP/1.1" 200 379

[11/Mar/2005:11:22:23 +0000] "GET /script.js HTTP/1.1" 404 296
[11/Mar/2005:11:22:23 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:11:22:23 +0000] "GET /mainlogo.jpg HTTP/1.1" 404 301
[11/Mar/2005:11:22:23 +0000] "GET /shared/bar_back.jpg HTTP/1.1" 404 308
[11/Mar/2005:11:22:23 +0000] "GET /main.html HTTP/1.1" 200 23745Firefox
[11/Mar/2005:11:25:26 +0000] "GET /style.css HTTP/1.1" 304 -
[11/Mar/2005:11:25:26 +0000] "GET /script.js HTTP/1.1" 404 296
[11/Mar/2005:11:25:26 +0000] "GET /mainlogo.jpg HTTP/1.1" 404 301
[11/Mar/2005:11:25:26 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:11:25:26 +0000] "GET /shared/bar_back.jpg HTTP/1.1" 404 308
[11/Mar/2005:11:25:27 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:11:25:27 +0000] "GET /shared/empty.gif HTTP/1.1" 304 -
[11/Mar/2005:11:25:27 +0000] "GET /shared/c-tl.gif HTTP/1.1" 304 -
[11/Mar/2005:11:25:27 +0000] "GET /shared/c-tr.gif HTTP/1.1" 304 -
[11/Mar/2005:11:25:27 +0000] "GET /cgi/poll/polls_image.gif HTTP/1.1" 304 -
[11/Mar/2005:11:25:27 +0000] "GET /favicon.ico HTTP/1.1" 200 246
[11/Mar/2005:11:25:27 +0000] "GET /main.html HTTP/1.1" 200 23745

[11/Mar/2005:11:25:29 +0000] "GET /page2.html HTTP/1.1" 200 379

[11/Mar/2005:11:25:31 +0000] "GET /script.js HTTP/1.1" 404 296
[11/Mar/2005:11:25:31 +0000] "GET /mainlogo.jpg HTTP/1.1" 404 301
[11/Mar/2005:11:25:31 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:11:25:31 +0000] "GET /shared/bar_back.jpg HTTP/1.1" 404 308
[11/Mar/2005:11:25:31 +0000] "GET /shared/yarrow.gif HTTP/1.1" 404 306
[11/Mar/2005:11:25:32 +0000] "GET /main.html HTTP/1.1" 200 23745

Things to note about the return to "main.html":-
1) Neither browser asks for the style sheets again.
2) Both browsers ask for the javascript again.
3) Some images are asked for again! Only some though!! Odd!
4) Firefox asks for some images TWICE on each display of a page! (Why is "yarrow.gif" loaded twice each time?)


Don't forget the purpose of this is to try and analyse what causes HITS. As we now have a newly introduced limit on this front some people, like myself, are actively trying to reduce unecessary hits.

Croc Hunter
3-11-05, 08:16 AM
What is the URL to your "'main.html" page, I will hit it with IE6 for comparisons. It all depends on how individual browsers handle files. The make, version, images on/off, security, and the visitors other settings will all make a difference - or not. Even ISP speed can alter results. Not one size fits all.

New visitors and repeat visitors who dump their cache regularly will call on, request, or "HIT" needed files every time.

NeilFawcett
3-11-05, 08:25 AM
What is the URL to your "'main.html" page, I will hit it with IE6 for comparisons. It all depends on how individual browsers handle files. The make, version, images on/off, security, and the visitors other settings will all make a difference - or not. Even ISP speed can alter results. Not one size fits all.

New visitors and repeat visitors who dump their cache regularly will call on, request, or "HIT" needed files every time.

The above examples are running on a personal machine running apache, so you won't be able to access it. I chose IE and FireFox purely as they are two popular ones.

What is interesting though:-
- The style sheets are not asked for on subsequent visits. Meaning keeping them as links is probably wise. This goes against the advice given by some people.
- If anything it appears to make more sense to include small javascripts that linking them in. They are HIT everytime.
- I would LOVE to know why some images are read everytime, and some are not.
- Surely it's a bug that FireFox retrieves the same image more than once (per page)?


I think what we need to be aiming at here is a clear set of methods for reducing hits. At the moment we have people making suggestions willy-nilly which infact are possibly mis-leading or even wrong!? Hopefully between a few of us we can do this?