Skip to content

Instantly share code, notes, and snippets.

@borissov
Created August 6, 2018 15:29
Show Gist options
  • Save borissov/250ef10ba7a7e34c8bcdc9ba0a284611 to your computer and use it in GitHub Desktop.
Save borissov/250ef10ba7a7e34c8bcdc9ba0a284611 to your computer and use it in GitHub Desktop.
Gzip assets in Laravel 5

First Install gzip Webpack plugin

npm i -D compression-webpack-plugin

In webpack.mix.js add plugin configuration:

const CompressionPlugin = require("compression-webpack-plugin")
  
mix.webpackConfig({
        plugins: [
            new CompressionPlugin({   
                  asset: "[path]gz[query]",
                  algorithm: "gzip",
                  test: /\.js$|\.css$/,
                  threshold: 10240,
                  minRatio: 0.8
            })
     ]   
    });

In .haccess file append in mod_rewrite section:

    # PreGzipped Files
    AddEncoding gzip .jsgz .cssgz
    AddType application/x-javascript .jsgz
    AddType text/css .cssgz

    RewriteEngine on 
    RewriteCond %{HTTP:Accept-Encoding} gzip 
    RewriteCond %{REQUEST_FILENAME}gz -f 
    RewriteRule ^(.+)\.(css|js)$ $1.$2gz [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment