Skip to content

Instantly share code, notes, and snippets.

@flyher
Forked from mccabiles/nginx.conf
Created June 28, 2021 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyher/424231038f7ee737538539f33d271b9f to your computer and use it in GitHub Desktop.
Save flyher/424231038f7ee737538539f33d271b9f to your computer and use it in GitHub Desktop.
Using gzip with Nginx and Vue CLI project
...
gzip on;
gzip_static on;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_proxied any;
gzip_vary on;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
...
// In vue.config.js:
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
module.exports = {
configureWebpack: {
plugins: [
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8
}),
],
},
};
@flyher
Copy link
Author

flyher commented Jun 28, 2021

and we can aslo add this code to zip/br code:

const CompressionPlugin = require('compression-webpack-plugin');
const zlib = require('zlib');

    plugins: [
      new CompressionPlugin({
        filename: '[path][base].br',
        algorithm: 'brotliCompress',
        test: /\.(js|css|html|svg|ttf|woff|woff2)$/,
        compressionOptions: {
          params: {
            [zlib.constants.BROTLI_PARAM_QUALITY]: 11,
          },
        },
        threshold: 10240,
        minRatio: 0.8,
        deleteOriginalAssets: false,
      }),
    ],

https://webpack.js.org/plugins/compression-webpack-plugin/

SimenB/add-asset-html-webpack-plugin#171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment