Understanding Static and Dynamic Caching

Mychelle Blake
Interaction between users, computers and servers.
The static and dynamic interaction between user and a website.

Static and dynamic caching are two concepts that are important to understand when setting up a site, because they can significantly impact not only a user's experience, but also your server usage.

What Is a Cache?

hand pointing at search bar

Caching is a method of storing data that internet browsers use. When you visit a website, your web browser pulls data from that site and holds it in a cache in order to improve the speed at which the site loads.

For example, if you decide to click to another page on the same site, and then go back to a previous page, because your browser is holding the data from that first page, the images, text and other media will show quickly on your screen. If the computer had to access, download and render the same files every time, performance would be compromised. The more media-rich the page is, the slower the site would be as those items would have to be accessed and re-read over and over.

Cache is also why you sometimes have to "refresh" or "clear" your cache; your browser is storing information previously accessed that you may have since updated, such as a password, and the new information is interfering with the old data.

Static Cache

A static cache is when information is provided to your browser in its most easily accessible form. There are no complicated codes that need to be executed and the files generally are made up of HTML, CSS, JavaScript and media files (like images and video).

A simple website with no special features that change with user actions, like typing in data, might utilize a static cache. If you want to create an "information only" website, then static caching is the best option. A user on a static site could look up information from the site's database using a search function, but they would not be able to manipulate the data in any way.

Dynamic Cache

A dynamic cache involves much more complex code and processes that increase the work for your browser and can slow down performance. It is best used for sites that are providing content that changes depending on the actions of the specific visitor.

Examples include sites that have login screens with user or member profiles, or sites with content that can only be viewed by users with different roles. It also would include sites where you can access data, edit it, and save it to the site's database.

Forum sites and social media sites, such as Facebook, are also examples where dynamic caching is used. Sites that need to pull data from an API, such as Google Maps, utilize a dynamic cache too.

Differences Between Static and Dynamic Caches

Finger on trackpad of computer

The easiest way to understand how these two technologies differ is to consider the concept of interactivity.

One or Two-Way Communication?

If you were to draw an arrow between a picture of a user and a computer, with the arrowhead symbolizing the direction of data transfer, it would only point toward the user in a static cache situation. The user goes to the site, looks up information and receives that information on a page. Only the information on the page has been prepared ahead of time with that particular data.

On a dynamic site, the arrow points both ways. The user enters information on the page, and the site returns that information, as well as suggestions for other types of information, or other data based on the user requests. At the same time, the user can not only look at the data, but they can also change, delete or add to it.

Any site with user profiles where you need to log in or change your information is using dynamic cache. If the website needs to return dynamic results based on user input, rather than simply delivering ready-made files, it is also using dynamic cache.

Not Mutually Exclusive

Most websites do not purely use one cache or the other. You are most likely to find sites where some of the data is prepared and ready to go, while other data is created dynamically.

When you read an About Us or FAQ page on a company website, you are receiving flat, static files when you click on the corresponding links. On that same site, there may be a store where you can create an account, log in, and make purchases when you are ready to buy. That part of the site is dynamic.

Sites using dynamic cache can run more slowly due to the more complex processes taking place in the back-end. If your server is not set up properly, you can run into issues with slow performance and even crashes if the server gets overwhelmed with too many data requests. On the other hand, these sites can do more for a client and create a higher degree of user interactivity, which is more likely to convert users to long-term clients.

Which One Should You Use?

If you are looking to create a site that does not require interaction with the user and is purely meant to provide data, a static cache is probably the best way to go. It's the least server-intensive and is the fastest option, assuming everything on your site is optimized correctly.

Otherwise, a site that uses a mixture of static and dynamic caching is the most effective option for a site that will interact with the user and create a more personalized experience.

Understanding Static and Dynamic Caching