This is the third day of my participation in the August Text Challenge.More challenges in August

The original intention of this series of articles is to “let each front-end engineer master the high frequency knowledge, for the work of power”. This is the front end of the number 35 cut, I hope friends pay attention to the public number “kite”, armed with knowledge of their minds. I will tell you in advance that the PDF version of the first 100 questions is coming soon (^_^)

The resource with strong cache will not be verified to the server, so there are some problems, that is, the resource update problem during the release. After the resource is updated, the user still obtains the original resource from the cache every time the user requests it. Unless the user clears or forcibly refreshes the resource, the latest effect cannot be seen.

4.1 Solutions and disadvantages

  1. Using 304 Redirect redirect, let the browser’s local cache be the negotiated cache.

Disadvantages: Negotiating the cache still requires a communication with the browser.

  1. Forces the browser to use the local cache and not communicate with the server.

Disadvantages: Unable to update the cache.

  1. By updating the resource path referenced in the page, let the browser voluntarily abandon the cache and load the new resource. For example, add a version number to the end of the file name and change the version number the next time the file goes online.

Disadvantages: When there are multiple static cache files and only one file changes, all files need to be updated.

In order to solve this problem, data summarization algorithm is used, that is, the modification of URL is associated with the content of the file, that is, only when the content of the file changes, the corresponding URL will change, so as to achieve precise cache control at the file level.

4.2 Scenarios where pages and resources are updated simultaneously

In order to further improve the website performance, static resources and dynamic web pages will be deployed in clusters. Static resources will be deployed to the CDN node, and resources referenced in the web page will also become the corresponding deployment path. When I update static resources, I also update references in the HTML. If this release, at the same time changed the page structure and style, but also updated the url address corresponding to static resources, join the use of coverage release, now to release the code online, we should first online page, or first online static resources?

  1. Deploy the page first, then the resource: In the interval between deployment, if a user visits the page, the old resource is loaded in the new page structure and cached as the new version, resulting in: The user visits a page with a bad style, and unless manually refreshed, the page will continue to execute errors until the resource cache expires.
  2. Deploy resources first and then pages: Within the deployment interval, users with the local cache of resources of an earlier version visit the website. Because the requested page is of an earlier version and the resource reference is not changed, the browser directly uses the local cache. In this case, the page is displayed normally. However, users with no local cache or expired cache will visit the website, and the old version of the page will load the resources of the new version, resulting in page execution errors. However, when the page is deployed, these users will visit the page again and it will be normal again.

This is a problem for anyone who deploys first, because overwriting published resources with resources to be released is a problem. It is easy to solve this problem by implementing non-overwrite publishing.

4.3 extensions

You can perform the following operations to optimize static resource deployment:

  1. Configure extremely long local caching – saves bandwidth and improves performance

  2. Use content summaries as the basis for cache updates – precise cache control

  3. Static resource CDN deployment — Optimizing network requests

  4. Update the resource publishing path for non-override publishing – smooth upgrade

1. If you think this article is good, share and like it so that more people can see it

2. Pay attention to the public number of kite, and the number of the Lord together to kill the front hundred