Speed up your website with Web Cache!

Posted by Anant Sharma under Web Development on March 27, 2020

Is your website loading slow? Do you know majority of the visitors expect a website speed page load in 2 seconds or less…

So what can be done to help your website load faster and lower the load impact on the server? The answer is simple – make a cache of your website!

Website Cache

To understand why cache is necessary, one must first understand that how a dynamic page from a website is served. Firstly, when a request is made for the page or in a layman language a website is searched and clicked, then PHP generates that page while making database requests to generate the HTML output, which is then served to the visitor’s browser. If no caching is set up, then each time the request is made, the page is generated again and again thus increasing unnecessary server load and ultimately slowing the loading time of the page.

What caching does is that it stores the HTML output generated by the first request and then serves that output to the subsequent requests. This in turn eliminates or minimizes the need to call PHP or Database queries, which ultimately benefits in fast loading and reduced server load.

With caching enabled, the server can handle large number of requests with ease.

Cache types

Web Caching can be broadly classified in two parts :

  • Server side Cache
  • Browser / Client side Cache

Server side Cache

In Server side Cache, generally the output of the page is generated on the Server and the page is served from the Server. This can be further classified into 4 broad types:

  • Page Cache
  • Object Cache
  • Opcode Cache
  • Database Cache

Page Cache

Page cache is the most widely used server cache type, it is also the most efficient one. In this one, the cache of the whole page is generated and served to the visitor’s browser. Cached Page can be stored on Disk or in Memory. Serving cached pages from memory is faster than disk.

Object Cache

Object cache is used when only some elements needs to be cached on the page, this is useful if many of the page components are dynamic and needs to be refreshed multiple times, whereas some areas of page remains static, so they can be cached to improve performance.

Opcode Cache

Opcode cache is a powerful tool, it caches the result of PHP code compilation to bytecode. In layman terms, PHP is interpreter based language, i.e. in PHP each line of the code is converted to bytecode in runtime, but this happens every time a PHP script is invoked. When there are large number of requests, this causes a performance penalty. With Opcode cache this need is eliminated as the cache of complied code is already present in the server, which is then served, thereby reducing load.

Database Cache

With Database Cache, the most used database query results are cached in either Disk or Memory, so that the need for database calls is minimized. This in turn reduces database load since it only has to serve limited queries thereby increasing performance.

Browser / Client side Cache

A web browser temporarily stores the resources such as javascript, css and images on the local computer, and this is known as Browser cache. When a website is requested for the first time, the browser will try to store its CSS, Scripts and Image files in local computer, and once this is done, the next time another page of the website is loaded or the same website is requested again, the browser will not make a request to the server, but will try to serve the resources from its local cache on the device, thereby loading the pages much faster.

These are the basic highlights of web caching for a website which translates into faster load times and lower server load.

Out next upcoming article will further explore Caching options for WordPress based sites …

Recent Posts

Top 5 Web…

Blog | 11 December 2024

We are Hiring…

Careers | 22 October 2024

Hiring Digital Marketing…

Careers | 20 March 2024