[Webpack 2] Hashing with Webpack for long term caching

Source: Internet
Author: User
Tags browser cache

Leveraging the browser cache is a important part of page load performance. A great the utilize-to-versioning your resources. In this lesson, learn how to use Webpack's hashing feature so you can take advantage of a long term caching of your of.

Install:

NPM install-d Html-webpack-plugin

Webpack.config.js

const {Resolve} = require (' path ') const Htmlwebpackplugin = Require (' Html-webpack-plugin ') Const Istest= Process.env.NODE_ENV = = = "Test"; Module.exports= ENV = {  return{entry:'./js/app.js ', Output: {filename:' Bundle. [Chunkhash].js ', Path:resolve (__dirname,' Dist '), PathInfo:true,}, Context:resolve (__dirname,' SRC '), Devtool:env.prod? ' Source-map ': ' eval ', module: {loaders: [{test:/\.js$/, loader: ' Babel!eslint ', exclude:/node_modules/}, {test:/\.css$/, loader: ' Style!css '},],}, plugins:[New Htmlwebpackplugin({Template:'./index.html '            }        )    ]  }}

Remove Bundle.js in index.html

Then in the browser can see the bundle file with hash name. So everytime, your change the source code, it'll update automatically

[Webpack 2] Hashing with Webpack for long term caching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.