When dealing with a Web application, the web server is our gateway to the application server. The best practice to separate the load between application code and static files are the task of the web server. This to make sure the application server just handle the thing they good of, the application. Let the burden to handle the serving of static files be lifted from the application server. Have mercy for the application server.
So the best practice is the static files handled by web server directly, and the application generated content goes to the application server. Now the load already separated. Now to get more of your application speed, we want to control how long the static files get cache by the client browser.
The question is can this be done? Yes this is can be done, this is included in the HTTP protocol specification rfc7231. We can control how long the request result will be cached by user web browser, and newer web browser will respect this header if ever appear in the http request results.
So the directive can be use are :
cache-control: private, max-age=0, no-cache
This means cache-control is active.
The private directive means the request should not be cache by shared cache like proxy server. But the local private cache can do the caching.
Max-age means the maximum age of the request result that considered valid since first request result arrived in client and can be used by the client.
no-cache means don't do any caching in client web browser. The browser will always fetch the new content from the web server.
Note if you want to increase the max-age, then remove the no-cache directive.
This can be applied to any webserver, including Microsoft IIS without change anything in the registry. The same with Nginx or apache or lighttpd.
Good luck and happy serving web content.
0 comments:
Post a Comment