Forum Moderators: open

Message Too Old, No Replies

Caching identical code

I want certain blocks of code to be cached - How can I do that?

         

MatthewHSE

2:39 am on Aug 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

After hearing how browsers cache stylesheets, using either the <link> or @import procedure, I decided I'd like to look into caching more of my site.

For instance, I have an identical header and footer on most of my pages. The code is exactly the same on each and every page. Thus, there's really no need for the browser to take time to download that code page after page.

I thought about using SSI, but then remembered that those files are done at the server level and the browser never knows they exist. So I guess an SSI file won't be cached.

I have no other ideas for caching that code, however. Does anyone else know a way?

Also, my header and footer include rotating banners. I can call them with an SSI, but the way I see it, that may complicate things since the banner portion of the header and footer will be different for each page.

I haven't seen this addressed anywhere else - would love to see some discussion on the topic though!

jdMorgan

2:46 am on Aug 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Matthew,

As you have surmised, SSI is treated as part of the page, and not as a separate, cacheable entity. External JavaScripts are cacheable, but then you run into the problem of user-agents and robots which do not support JS, or users who have disabled it.

Except for external client-side scripts, external stylesheets, and shared images, you basically have to think of browser caching at the page level.

Here's a decent caching tutorial [mnot.net], with a link to a useful cacheability checker script.

Jim

gph

3:25 am on Aug 22, 2003 (gmt 0)

10+ Year Member



MS FrontPage "Include Page" might do it. I'm pretty sure they're treated as a normal HTML page regarding caching. I know they don't need js or a server but I don't know if bots see them.

g1smd

10:45 am on Aug 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I believe that MS FP just builds the includes into the page before they are sent to the server in most cases, but that there is also some way to configure the server to include them, when served, instead (but this relies on the server running MS code <like IIS?> and FP extensions).

I'd think that you would get more mileage out of PHP from the basic stuff I have read about it.

jamie

12:09 pm on Aug 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



remember when thinking about cacheability of a page, the Headers which are sent are very important. if no last-modified or expires headers are sent, then no browser can ever cache your page, it always has to download the newest version. this can be a problem when using SSI or PHP.

with regard to SSI do a search for XBitHack in this site - jdmorgan has already written some great stuff about it. as for PHP and headers, if you are interested there are quite a few posts about this in the current php forum.

probably the easiest way to reduce the ammount of code sent to the browser is by emplying the apache module mod_gzip. this can compress html code up to 80% - so you get a page which normally contains 20 kb of html code, this is compressed down to 3 or 4 kb. this makes for great savings on download times - especially on big weighty html pages with lots of text.

be aware that mod_gzip'ing all your pages before sending them to the browser needs more CPU resources. e.g. i have had to turn it off for all pages under 15 kb on our server, as it brought our server to its knees (we have a 2.2 ghz cpu and serve 100,000 pages a day)