Search
Left Quote    You have to THINK anyway, so why not think BIG?
- Donald Trump    
Right Quote
 
[login] | [Register]
Forum Index » HTML and CSS » Viewing Topic and Replies
Post Reply


        Viewing Topic: css files and browser caching
  This user is offline  misterhaan
  Subject: "css files and browser caching" Posted: @ 7:55 pm on Jun 15 2005   

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

i used to have one incredibly large css file containing styles for my entire site, but i decided there was no need to make visitors download style information for stuff they might never even see. so now i came up with this system where i put all the general stuff in general.css, then stuff specific to a certain directory in dirname.css, and stuff for just one page is in dirname-pagenam e.css. each then @imports the next lower stylesheet (except of course general.css). my php page header code finds the most specific css file and drops that in the head tag for the page, so now only styles actually needed by the page are getting loaded (plus whichever general styles the page isn't using).

the only problem is that i'm also using php to generate my css files, so they don't get cached! i don't expect that they will change frequently, so i'll look into sending the right headers so that the browser tries to cache them.

anyway i thought i'd share this idea of splitting up css information to help pages load faster. i should probably also point out that i very rarely put any style information in the actual page itself, which got me a 24-kb css file (which was also generated through php, and so was getting re-downloaded with every page request).


please note that the above post is likely made up in its entirety.
    Viewed: 8,186 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: css files and browser caching" Posted: @ 9:23 pm on Jun 15 2005    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

i figured out how to get php to do the caching (and hopefully it's telling shared proxies not to cache it), so my site is probably faster now




please note that the above post is likely made up in its entirety.

    Viewed: 8,182 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: css files and browser caching" Posted: @ 4:00 pm on Jun 16 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

I think you might still have an error in that. I checked the site in IE and it woudnt load your CSS. I posted in your forums. But once you get it working that sounds like a good idea. I should try to do the same.

How did you get php to do the caching?




-bs0d | AllSyntax.com

    Viewed: 8,172 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: css files and browser caching" Posted: @ 4:30 pm on Jun 16 2005    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

 bs0d said...

< i>How did you get php to do the caching?

i got it to do it wrong

but now i fixed it, so it's all good. i explained what i did wrong in the thread on my forum if anybody's interested.

basically, to get a browser (or a proxy server) to cache your content, you have to tell it when it last changed. this is done with the Last-Modified header, and has to be in the format 'D, d M Y H:i:s T' -- i think it also needs to be GMT, but i didn't try any other time zone. once a browser or proxy receives a file with this header, it sends a If-Modified-Sin ce header on subsequent requests with the date it got in the Last-Modified header. now if your file has not changed since the date in If-Modified-Sin ce ($_SERVER['HTT P_IF_MODIFIED_S INCE']), you just send a header 'HTTP/1.0 304 Not Modified' and kill your script. the browser/proxy sees that and uses the cached copy.

i had a couple issues that made this slightly more complicated for me. first is that all my stylesheets are including a php file which sets some constants with the colors to use (this is how i have 4 different color schemes available). i put all the cache control code in there, so that was actually nice
it did make getting the correct value for Last-Modified slightly more complicated though -- i have to check filemtime() on both the css file and the include file, and use the more recent value. also, my include file sets some flags for if the browser is ie or opera based on useragent, so i don't want a proxy server caching the ie style and sending it to opera and firefox. this is (supposedly--i have no way to test it) handled by the Cache-Control header, which is 's-maxage=0, proxy-revalidea te' from what i can tell, this means that shared caches should consider the file fresh for 0 seconds, and that proxies should always obey that rule.

of course if you don't use php in your css files, the server sends the appropriate headers for you




please note that the above post is likely made up in its entirety.

    Viewed: 8,167 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank