Caching - Page Speed Best Practices (2024)

  1. Home
  2. / Web Best Practices
  3. / Page Speed Best Practices
  4. / Caching

Caching should be used to decrease server load and reduce the amount of data browsers need to download while browsing your site.

Fetching something over the network is both slow and expensive. Large responses require many roundtrips between the client and server, which delays when they are available and when the browser can process them, and also incurs data costs for the visitor. As a result, the ability to cache and reuse previously fetched resources is a critical aspect of optimizing for performance.

Caching - Page Speed Best Practices (2)

Want to know when we write new articles? 😄 Get news and updates about web best practices from us via

Twitter,Facebook orour newsletter.

Use caching

Enable caching of your page resources so browsers can reuse resources that have already been downloaded. The Cache-Control response header is used to specify the caching policy of each URL: the no-store setting prevents all browser caching and the no-cache setting forces the browser to check with the server if a cached version is out-of-date before using the cached copy. For page resources, we recommend that no-cache and no-store are not set. This configuration means a browser will always cache resources and will immediately reuse them if needed without having to contact the server again. Warning: You must have a strategy for how updated versions of your page resources are going to replace the cached versions. Generally, each updated resource should use a new URL to force browsers to fetch the new version. This is referred to as “cache busting” and is built into many web frameworks.

Use long caching times

Configure page resources to have long caching times so browser caches will retain them for longer. The cache duration of each resource URL can be specified by either 1) setting an Expires response header which specifies the point in time the response becomes stale such as Expires: Fri, 10 Aug 2019 20:00:00 GMT or 2) adding a max-age directive to the Cache-Control response header that specifies the number of seconds the response is valid for such as Cache-Control: max-age=3600 for 1 hour. If max-age and Expires are both used, max-age takes priority. We recommend setting the cache time of page resources to at least 24 hours.

Learn more

  1. Expires - HTTP Headers

    developer.mozilla.org

  2. Cache-Control - HTTP Headers

    developer.mozilla.org

  3. HTTP Caching

    developers.google.com

  4. HTTP caching

    developer.mozilla.org

  5. Caching in HTTP

    www.w3.org

  6. Increasing Application Performance with HTTP Cache Headers

    devcenter.heroku.com

Avoid duplicate resources

The same page resource should always be served from the same URL to improve caching efficiency. Browsers will only reuse a cached resource if the resource is requested from the exact same URL as before. If the same resource is available over multiple URLs, this can lead to extra browser requests. For example, say a browser cached a resource from http://example.com/jq.js and later had to request identical content from these URLs while browsing (where the URL differences are highlighted): https ://example.com/jq.js, http:// www. example.com/jq.js, http://example.com/ jquery .js, http://example.com/ libs/ jq.js, http://example.com/jq.js ?v=3.2&a=1, http://example.com/jq.js ?a=1&v=3.2. As none of the URLs are exact matches, the same content would need to be downloaded when each URL was first seen as a cached response from a different URL cannot be used instead. For caching to happen, URLs must have matching protocols, filenames, folders, query parameters and even query parameter ordering. Avoid caching issues like this by making sure each unique page resource is referenced using a single consistent URL.

Learn more

  1. HTTP Caching

    developers.google.com

  2. Increasing Cache Hit Rates with Query String Sort

    blog.cloudflare.com

More articles in this series

➜ This article is from our comprehensive Page Speed Best Practices guide.

➜ Next article in this series: CSS

➜ Previous article in this series: Page size

Want to know when we write new articles? 😄 Get news and updates about web best practices from us viaTwitter,Facebook orour newsletter.

Caching - Page Speed Best Practices (2024)
Top Articles
How to declutter books – 10 novel ways to streamline your collection
U.S. – Mexico – Canada Agreement (USMCA) Frequently Asked Questions
St Thomas Usvi Craigslist
Srtc Tifton Ga
Cappacuolo Pronunciation
123Movies Encanto
فیلم رهگیر دوبله فارسی بدون سانسور نماشا
Crossed Eyes (Strabismus): Symptoms, Causes, and Diagnosis
Ventura Craigs List
50 Meowbahh Fun Facts: Net Worth, Age, Birthday, Face Reveal, YouTube Earnings, Girlfriend, Doxxed, Discord, Fanart, TikTok, Instagram, Etc
Retro Ride Teardrop
270 West Michigan residents receive expert driver’s license restoration advice at last major Road to Restoration Clinic of the year
shopping.drugsourceinc.com/imperial | Imperial Health TX AZ
Clairememory Scam
What Does Dwb Mean In Instagram
Colts seventh rotation of thin secondary raises concerns on roster evaluation
Bjork & Zhulkie Funeral Home Obituaries
D10 Wrestling Facebook
Hell's Kitchen Valley Center Photos Menu
Midlife Crisis F95Zone
Pac Man Deviantart
Air Force Chief Results
Wausau Obits Legacy
Officialmilarosee
Cvs El Salido
Big Lots Weekly Advertisem*nt
Myhr North Memorial
Knock At The Cabin Showtimes Near Alamo Drafthouse Raleigh
Danielle Ranslow Obituary
The Eight of Cups Tarot Card Meaning - The Ultimate Guide
Evil Dead Rise Showtimes Near Sierra Vista Cinemas 16
Tomb Of The Mask Unblocked Games World
130Nm In Ft Lbs
Big Boobs Indian Photos
Healthy Kaiserpermanente Org Sign On
Darktide Terrifying Barrage
Downloahub
LEGO Star Wars: Rebuild the Galaxy Review - Latest Animated Special Brings Loads of Fun With An Emotional Twist
A Small Traveling Suitcase Figgerits
Senior Houses For Sale Near Me
Zero Sievert Coop
Greater Keene Men's Softball
Is The Nun Based On a True Story?
Final Fantasy 7 Remake Nexus
303-615-0055
Craigslist Boats Dallas
Oppenheimer Showtimes Near B&B Theatres Liberty Cinema 12
Inducement Small Bribe
Secrets Exposed: How to Test for Mold Exposure in Your Blood!
All Buttons In Blox Fruits
Dolce Luna Italian Restaurant & Pizzeria
Round Yellow Adderall
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 5802

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.