Picto thématique

Rule n° 220 - The server sends information to enable the caching of contents

A server can accompany the sending of an HTML page or an image, Java- Script, CSS or other file, as well as information allowing them to be cached on the user workstation. To do this, it is necessary to configure it correctly, and everyone wins.

#Basics #Development #Server and performance #Eco-conception

Goal

  • Speed up the display of content and enable a smoother navigation experience.
  • Reduce bandwidth costs.

Implementation

Configure the web server so that it can manage the caching of static elements and manage, at the application level, the possible caching of dynamic elements.

In practice, and in accordance with the HTTP specifications, the server must send the corresponding etag, date and last-modified headers, to the identifier of the resource, to the date of processing of the request and to the date of the last modification, respectively, of the requested resource. All dates are in GMT format. This information can be supplemented by the content-length and expires fields if the size in bytes and the exact expiry date of the content are known.

In order to inform the proxies and the end clients about the behaviour to adopt in relation to cached content, developers should use the HTTP cache-control header in accordance with the necessary refresh times and the privacy of the delivery.

Possible caching can be finalised by submitting a 304 Not Modified message (without the requested resource in the request body), when the server receives an if-modified-since header containing a date prior to the modification date of the resource.

Control

For each page: check the possible caching of the page elements using a dedicated tool (development tools, online service, etc.) Be careful to check all of the linked elements (CSS, JS, images) and not just the page itself.

By Opquast - Read the license


Discover Opquast training and certification

The objective of these rules and the Opquast community mission is ‘making the web better’ for your customers and for everyone! Opquast rules cover the key major areas of risk that can negatively affect website users such as privacy, ecodesign, accessibility and security.

Opquast training has already allowed over 19,000 web professionals to have their skills certified. Train your teams, contact us

We offer a 1 hour free discovery module.