The Impact of Web Caching
Need a refresher on caching? Read on for the pros and cons of using web caching, and how to optimize your results to create a better UX/UI.
Join the DZone community and get the full member experience.Join For Free
try to remember something that happened on your last vacation. how long did it take you to recall? now, try to remember it again. you were probably able to recall it faster the second time— but, why? this is because as soon as you recalled the event the first time, your brain saved the information to your recent memory.
the same concept applies to caching. caching is a way of temporarily storing the contents of a webpage in locations near the user, similar to the way our memory works. there are several types of caching options available like database caching, application caching, distributed caching, etc. in this article, we’ll talk about web caching and how it affects user experience.
what is web caching?
web caching minimizes network traffic and improves the perceived performance of the webpage. caching can be implemented at different levels along the network path. the following are the possible caching entities between the origin server and the browser:
- local browser : your browser maintains a place on your hard disk where it stores content that is being requested frequently.
- isps or caching proxies : servers along the network path can cache the content. these servers can belong to either isps or any other third party.
- content delivery network (cdn): cdns make use of multiple networked servers to distribute the web content from locations closer to the users.
- proxy for your backend server: you can have your infrastructure built on top of your backend servers, which can cache all your content and act as a focal point for reducing the load on your backend server.
how do the caching entities know what to cache?
caching is implemented through an http headers directive, named “cache-control,” which is sent out in instances of http response headers. if the request is allowed to cache, entities will keep a copy of the page for a specified period, which helps the content owner determine the caching behavior. cache control lets the entities identify the response/request that can be cached and for how long.
syntax cache-control: public
here is an example of an http response with a cache-control header:
how does caching help in improving user experience?
user experience can have a direct impact on your brand; it can either build your online business or hinder its growth. there are several components that contribute to a satisfactory user experience. caching is an important factor to consider when optimizing website performance. it has the following advantages:
the load time of a website can be a cause for user frustration; pages that take a long time to load usually result in higher bounce rates; let us look at some of the stats:
- 51% of online shoppers in the us say that site slowness is the top reason they’d abandon a purchase.
- a 2-second delay in load time during a transaction results in abandonment rates of up to 87%.
the speed at which the webpage loads is crucial in ensuring a good digital experience and caching can reduce load time as it serves content from a location nearest to the users – either on the user’s hard disk or a nearby server.
the above image illustrates the impact of caching. as you can see, the page loads 50% faster when cached. caching reduces latency in the roundtrip time by retrieving the content much faster. the time taken to retrieve the resource from the cache will be lower than the time it takes from the origin server and this speeds up the content delivery process.
2. content availability
content availability is a key component in user experience as users from across the globe can access the website. a site may not load for a user due to several reasons – the network may be prone to frequent interruptions or the site may be experiencing intermittent outages. in such cases, caching will save the day by serving end users the cached content, making the website robust.
3. avoids network congestion
the internet handles huge amounts of data and manages heavy traffic through the day; as a result, bandwidth congestion can be an issue on major networks.
to understand this better, let’s use a restaurant as an example. assume that there is only a single location for this restaurant in the city, making it a crowded spot with customers coming in every few minutes. if the restaurant ends up exhausting all of its resources trying to manage everyone, service could be delayed as they are working above their existing capacity, resulting in a long line of customers waiting to be served. the restaurant would be able to manage better if they had more than one location in the city to help distribute the customers and balance the load.
the same logic applies to the internet as well. network congestion can be greatly reduced with caching, as the path traveled in fetching the content is cut short when it’s cached. since all the requests are not directed towards the origin, it frees up the network and reduces the load on the origin server, helping it serve non-cached content faster.
the image above demonstrates the difference in the number of requests with or without cache on the wire.
disadvantages of caching
the best practices for implementing a cache strategy are not strictly defined, so if caching is not set up correctly, then the browser will not be able to validate the cached content and the page may load outdated content, which can have a negative impact on the user experience.
caching entities include third-party proxy servers shared by multiple users which are always at risk of being compromised. if caching servers are hacked then it impacts all the users connected to this server.
troubleshooting caching issues
a performance monitoring solution has proven to be a very effective way of mitigating issues associated with caching. one of our own customers reported an issue in which users from certain locations were unable to use the search feature on their website. in this instance, the search results were blank.
- continuous evaluation of caching policies is important.
- always have cdn monitoring in place.
implementation of caching will help grow your business positively by being a vital cog in ensuring business sustenance. but at the same time, it is very important to ensure optimal caching policies are in place to suit your business. tailored solutions are the way to go because there is no one-size-fits-all solution. caching may not be the talisman, but it will ensure that your business stays afloat and affluent with minimal exertions.
Published at DZone with permission of Alva Yashaswi, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.