How to speed up your next js app using GZip

I am a full stack developer. Currently doing some project on nextjs / nodejs
Working as SDE 3 in Netomi Here’s my Resume: https://resume.devaman.dev
Search for a command to run...

I am a full stack developer. Currently doing some project on nextjs / nodejs
Working as SDE 3 in Netomi Here’s my Resume: https://resume.devaman.dev
No comments yet. Be the first to comment.
Recently i worked on Vue 3 migration. Migrating a Vue 2 application to Vue 3 is not just a dependency upgrade. The real work is in updating the application bootstrap, router, store, plugins, component

19/May/2023 While using mini-css-extract-plugin with vuejs and webpack 5, I was getting problem related to CSS priority. Scoped Css/Scss was not getting higher priority than common css. To resolve this issue we had to use oneof rule. In resourceQuery...

Hello everyone! I recently had the opportunity to work with AWS IoT to fetch real-time data. During the migration from Webpack 4 to Webpack 5, we encountered some issues with the aws-iot-device-sdk. While building our project, we encountered errors r...

Hey everyone , Webpack has released some new cool feature called module federation. Module Federation allows a JavaScript application to dynamically load code from another application and in the process, share dependencies. If an application consumi...

In this post I will tell you about on how to submit a pull request to the organization on which you are thinking to contribute. Now lets gets started with the steps... 1) Step 1 : Fork the repo. 2) Step 2 : Clone the repository.Open the terminal and ...

Amit Chambial Blog.
14 posts
Full Stack Developer and a maker. See my portfolio at https://portfolio.devaman.dev
Recently I was working on one of my projects built using nextjs . I was using semantic UI library. Even the minified version is too big for production. (631kb) It was making my web app slow. I searched through the internet for ways to reduce the size. Then I found out about gzip. I can encode my web app using gzip which reduced the size of the app significantly. Let’s see how to do it.
We need a reverse proxy. I was using NGINX. If we are serving static file from Nodejs server (express or koa) then we need to configure our nodejs server to serve gzip first if client browser supports gzip else server simple file
config.plugins.push(
new CompressionPlugin({
test: /\.js$|\.css$|\.html$/,
}),
);
The whole file will look like this
const withSass = require(‘@zeit/next-sass’);
const withCSS = require(‘@zeit/next-css’);
const CompressionPlugin = require(‘compression-webpack-plugin’)
const nextConfig = {
onDemandEntries: {
// period (in ms) where the server will keep pages in the buffer
maxInactiveAge: 50 * 1000,
// number of pages that should be kept simultaneously without being disposed
pagesBufferLength: 5,
}
}
module.exports = {
…withCSS(withSass({
target: ‘serverless’,
webpack (config) {
config.module.rules.push({
test: /\.(png|svg|eot|otf|ttf|woff|woff2)$/,
use: {
loader: ‘url-loader’,
options: {
limit: 8192,
publicPath: ‘/_next/static/‘,
outputPath: ‘static/‘,
name: '[name].[ext]'
}
}
})
config.plugins.push(
new CompressionPlugin({
test: /\.js$|\.css$|\.html$/,
}),
);
return config;
}
})
),
...nextConfig
}
# gzip config
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;
#
sudo systemctl restart nginx.app.use(express.static('public')). It only serves uncompressed files..To serve Compressed gzip file first we need to use express-static-gzip