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
Congressional salaries U.S. 2024 | Statista
Why retail arbitrage won’t help you scale your business
Dunhams Treestands
Sprinter Tyrone's Unblocked Games
Toyota Campers For Sale Craigslist
Bill Devane Obituary
Hope Swinimer Net Worth
Builders Best Do It Center
Shemal Cartoon
Dutchess Cleaners Boardman Ohio
The Banshees Of Inisherin Showtimes Near Regal Thornton Place
272482061
Operation Cleanup Schedule Fresno Ca
2016 Hyundai Sonata Refrigerant Capacity
Me Cojo A Mama Borracha
Lazarillo De Tormes Summary and Study Guide | SuperSummary
Iu Spring Break 2024
Unterwegs im autonomen Freightliner Cascadia: Finger weg, jetzt fahre ich!
Fraction Button On Ti-84 Plus Ce
NBA 2k23 MyTEAM guide: Every Trophy Case Agenda for all 30 teams
Gia_Divine
All Breed Database
Drug Test 35765N
Lines Ac And Rs Can Best Be Described As
Troy Gamefarm Prices
Spiritual Meaning Of Snake Tattoo: Healing And Rebirth!
4 Times Rihanna Showed Solidarity for Social Movements Around the World
Free T33N Leaks
Hobby Lobby Hours Parkersburg Wv
Combies Overlijden no. 02, Stempels: 2 teksten + 1 tag/label & Stansen: 3 tags/labels.
Cosas Aesthetic Para Decorar Tu Cuarto Para Imprimir
Where to eat: the 50 best restaurants in Freiburg im Breisgau
Gncc Live Timing And Scoring
Old Peterbilt For Sale Craigslist
The 38 Best Restaurants in Montreal
Skyrim:Elder Knowledge - The Unofficial Elder Scrolls Pages (UESP)
Raising Canes Franchise Cost
Aliciabibs
Boone County Sheriff 700 Report
Babbychula
sacramento for sale by owner "boats" - craigslist
Martha's Vineyard – Travel guide at Wikivoyage
Why Are The French So Google Feud Answers
Ferhnvi
Sandra Sancc
St Anthony Hospital Crown Point Visiting Hours
Iron Drop Cafe
Marine Forecast Sandy Hook To Manasquan Inlet
F9 2385
Gummy Bear Hoco Proposal
Causeway Gomovies
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.