0

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?

Uğur Gümüşhan
  • 2,455
  • 4
  • 34
  • 62

1 Answers1

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