Every time you navigate to other pages or reload one of them*, the browser must check if the resource has been changed or not in the server. If the resource is the same, the server doesn't have to send it again and sends a 304 status code (Not Modified); but if the resource has changed, then it sends the new resource
By default, nginx doesn't send to the browser the Expires
HTTP header, which tells the browser that the resource will not change over some period of time (giving him the ability to cache that resource and not asking for it over that period).
So if you know you have some resource that are unlikely to change, you can configure nginx to send the Expires
header. For example, if you want the user's browser to cache all images, CSS and JS on your site for one month, you can add the following to the nginx server configuration:
location ~* \.(?:css|js|png|gif|jpe?g|ico|svg)$ {
expires 30d;
}
If you update any of those files, browsers won't download the new version until the expires period is over. To avoid that and bypass browser's cache you can add a timestamp (or any other parameter) to your files. You can append to the URI the timestamp after a ?, so you don't have to change the internal name of that file on the server.
*Note: When you reload a page, browsers will check if the resources have changed, even if a Expires
header was sent when they were downloaded.