• Home
  • Long-term caching with Webpack

Long-term caching with Webpack


I am going to show you simple way to cache public files. Using this configuration bellow, we are instructing our server and browser to cache the file for as long as possible.

var webpack = require('webpack');
var path = require('path');

module.exports = {
    entry: {
        app: './src/app.js'
    output: {
        path: path.resolve(__dirname, './build'),
        filename: '[name].[chunkhash].js' 
        // chunkhash is only going to change if file is changed

    // clean directory from old builds using CleanWebpack plugin
    plugins: [
        new CleanWebpackPlugin(['build'],
            root: __dirname,
            verbose: true,
            dry: false,

About the Author

Follow me

30 year old software developer from Mostar, Bosnia and Herzegovina, currently living and working in Frankfurt am Main, Germany.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}