What is the purpose of webpack [hash] and [chunkhash]?

Can someone tell me what the purpose of [hash] and [chunhash] is and where did they come from?

output: { path: "/home/proj/cdn/assets/[hash]", publicPath: "http://cdn.example.com/assets/[hash]/" } 
+5
source share
1 answer

This is mainly related to browser caching - when servicing assets, you usually want to tell the client / browser that they can use the same script / stylesheet / jpeg, etc., without loading it every time. This is done by sending the appropriate HTTP header fields.

The problem is how long should you tell the client that they can continue to use the same stylesheet? If you redesign your site and do not upload a new stylesheet, they will not see these changes. Usually this solution adds some identifier or version number to the name of the stylesheet file - if this identifier / version changes when the stylesheet is changed (and therefore the file name is different), the browser will load it again (this is called the cache search).

Basically, webpack can add a hash to the package exit name, which, as a function of the package contents, will differ when the contents change, thereby automating the process. chunkhash does the same if you break a package into several pieces.

Here are a few non-webpack discussions: CSS CSS Caching Strategies

+3
source

Source: https://habr.com/ru/post/1242199/


All Articles