I am developing a website which is extensively using jquery dom javascript ajax etc. I am dividing the javascript files to be cached and it saves me around 0.2 seconds, also, I have templates on the main page, which are hidden and I switch between hidden and visible, when I want to use these elements on the page, (like div or table, some elements which are selected and inserted into another content div", but I want to load these static templates from a file, so that the browser gets the file, and on page refreshes, the browser laods the static html file from cache, and It will save me a lot of miliseconds this way. but I don't know if current browsers assume htm files are static. I am helping the browser to assume the file is static, by saving it as *.htm , instead of *.php. What file extensions should I use, for making the browser assume they are static files? would htm be assumed to be static? Would you suggest using *.txt?
Asked
Active
Viewed 68 times
0
-
Ooh, milliseconds... I can totally tell the difference when a page takes *a few milliseconds* longer to load... – Niet the Dark Absol Apr 06 '12 at 23:39
-
@Kolink my competitive advantage against the rival site is speed. I would like to listen if you have any ideas about browser caching. – Uğur Gümüşhan Apr 06 '12 at 23:41
-
If speed is the only advantage you have... perhaps you should try to have content that people are willing to wait a fraction of a second longer for? – Niet the Dark Absol Apr 06 '12 at 23:42
-
1@Kolink maybe dial down the snark a little? – John Carter Apr 07 '12 at 01:34
1 Answers
2
You just need to set the correct HTTP caching headers on your files when you serve them.
https://developers.google.com/speed/docs/best-practices/caching
For static files you can configure your webserver to do this (eg Website image caching with Apache), for dynamic files you can do this on the fly (in PHP with the header()
function).
Note that the file extension doesn't really matter either, you should tell the browser what the type of files is using the Content-Type
header (though the extension will help your webserver guess this).

Community
- 1
- 1

John Carter
- 53,924
- 26
- 111
- 144