The content has not changed and the page is still slow, check the max-age and s-maxage of the cache headers first.
The content has not changed but the page still loads slowly, should the cache control header check max-age or s-maxage first? First, clarify the hierarchy and then discuss the order: max-age manages the freshness period of the response in private caches like browsers, while s-maxage only manages shared caches like CDN, and it will override the max-age value for shared caches.If your users are saying 'I open slowly', the first step is to check max-age; if all users are slow and the source site load is normal, the first step is to check s-maxage and shared cache hit status.The real answer is not either/or, but first locate where the slow occurs.
First determine if the slow is in transmission or rendering
In the network panel of the browser developer tools, look at two numbers: the time to first byte (TTFB) and the total download time. TTFB is large, slow on the server or chain, it belongs to the problem that needs to be solved by the cache header; TTFB is normal but the total time is dragging, slow in terms of resource volume and quantity, it is a matter of rendering side, changing the cache header is not useful. This step is wrong in direction, and any further detailed search is in vain. Take a look at the comparison after a hard refresh: a hard refresh bypasses local cache, if a hard refresh is明显 slower, it means that the browser cache has been working for you, the problem is concentrated on the first visit or shared cache layer.
Looking from the browser side at max-age
The semantics of max-age as defined by the standard is: the response remains fresh for N seconds after its creation. It only answers whether the browser is willing to use the locally stored copy directly.Content does not change but is slow, there are three common problems: the max-age value is too short, it always returns to the origin negotiation every time it is opened; The response is simply without cache instructions, the browser handles it heuristically, and the behavior is uncontrollable;There is a no-store interface call mixed in, turning reusable data into a full download every time. The action is to check the Cache-Control header in response headers resource by resource, separating the evaluation of static resources and document requests, and the freshness period of static resources should be significantly longer than that of documents.
Looking from the shared cache side at s-maxage and no-store
When the site is behind a CDN or enterprise gateway, pay special attention to s-maxage: it indicates the duration for which the response remains fresh in the shared cache, the private cache ignores this directive, but it overrides max-age for the shared cache.This means a typical accident: you reduced the max-age to make the content update as soon as possible, but s-maxage is still holding a long-old value, and the user still sees the old cache.Reverse the s-maxage is too short, CDN is as good as non-existent, each request is pushed back to the source, and everyone becomes slower. There is also a more severe killer, no-store - any type of cache is not allowed to store this response, once mistakenly attached to the document route, CDN and browser will all fail, and the source station will bear all the visits.Check such issues by following the routing order from 'user to origin server': browser, shared cache, origin server, only asking if the instructions at each level are correct.
At the origin server, confirm the static file and backup range
Troubleshooting at this level of the source station, the problem often changes from 'cache header' to 'source station itself slow': is the page rendered dynamically every time, have the static files truly become static products, and is the database query using an index.The degree of staticization of the content management system directly determines the response speed of the source site. Only sites with this layer problem-free are worth continuing to tweak the cache header seconds. Additionally, there is a check that is often confused but unrelated to caching: if 'slowdown' occurs after a migration or recovery, first confirm whether the backup range is complete - whether the backup and recovery of data containing static files have been verified. The recovery without static files will cause the site to generate the page that should be generated on the spot during operation, looking like cache failure.Based on Go language, AnQiCMS page loading speed is significantly improved compared to traditional PHP CMS, the official figure can carry about 5 million PV on a single machine, the confidence of the source station layer comes from this kind of architecture choice, the cache header just takes this ability further.
Common questions
Question: When max-age and s-maxage conflict, whose side should be listened to?Answer: The shared cache listens to s-maxage and overrides max-age; the browser's private cache ignores s-maxage and only recognizes max-age.
Question: How should the cache headers be configured for a column with frequently updated content?Answer: The document layer is configured with a short freshness period, and static resources are given a long freshness period. After updating, it relies on active link push and sitemap to allow search engines to quickly get the new version.
Question: When is 'no-store' appropriate?Answer: Responses such as login status private data, payment receipts, and the like; attaching them to ordinary document or resource routes is a performance issue.