Tuesday, October 20, 2015

Web site performance caching

                  

web cache (or HTTP cache) is for the temporary storage (caching) of web documents, such as HTML pages and images, to reduce bandwidth usage, server load, and perceived lag.

The ability to cache and reuse previously fetched resources is a critical aspect of optimizing for performance.

There are 2 types of cache scenario

Empty cache scenario and Primed cache scenario


























There are 2 types of caching Headers
Expires Header
  • Back in the day, this was the standard way to specify when an asset expired.
  • Tell the browser whether they should request a specific file from the server or whether they should grab it from the browser's cache.
  • They tell the browser how long to store a file in the cache so subsequent page views and visits they don't have to download the file again.
  • You can set Expires headers on specific files or even file types
Thu, 01 Dec 1983 20:00:00 GMT
Cache-Control  
  •  We can specify the cache age in seconds
  •  was introduced in HTTP 1.1
cache-control: private, max-age=0, no-cache
The browser would receive the last Modified : Mon,01 Dec 1983 00:21:02 header with a timestamp when the file was last modified in the server--> allows for conditional refersh





Note: In case of IIS we need to configure caching in web.config file.it  would automatically figure our out which header to apply

Conditional request for cached resource


  1. Even if the content has been cached the  browser checks with the server for the cached resource. 
  2. If the requested content has not been updated then the server sends a 304 status code.
  3. If it has been modified then it sends the content along with 200 status code




we cannot reply on this process as it sometimes fails to get the new content.
To accomplish this we need to use cache broker by giving the content a new name

 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.1.2.js"></script>
 
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.1.3.js"></script>  

Note: We can also generate unique name using has value

No comments:

Post a Comment