VPS server configuration

How to use gzip bundle.js in reactJS server side rendering

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #120
    Murali
    Keymaster

    Below is the code to run reactjs server side rendering with gzipped bundle.js file,

    Below code gives response headers with gzip which will load website/webapp faster using gzipped javascript and css files. Below code needs to be in expressjs server side starting script

    app.get('*.js', function(req, res, next) {
      req.url = req.url + '.gz';
      res.set('Content-Encoding', 'gzip');
      res.set('Content-Type', 'text/javascript');
      res.set('Access-Control-Allow-Origin', '*');
      res.set('Access-Control-Allow-Headers','Origin, X-Requested-With, Content-Type,Accept, Authortization');  
      res.set('Acces-Control-Allow-Methods','GET, POST, PATCH, DELETE');  
      next();
     });
    
     app.get('*.css', function(req, res, next) {
      req.url = req.url + '.gz';
      res.set('Content-Encoding', 'gzip');
      res.set('Content-Type', 'text/css');
      res.set('Access-Control-Allow-Origin', '*');
      res.set('Access-Control-Allow-Headers','Origin, X-Requested-With, Content-Type,Accept, Authortization');  
      res.set('Acces-Control-Allow-Methods','GET, POST, PATCH, DELETE');  
      next();
     });
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Manage push notifications

notification icon
We would like to show you notifications for the latest news and updates.
notification icon
You are subscribed to notifications
notification icon
We would like to show you notifications for the latest news and updates.
notification icon
You are subscribed to notifications
Would you like to install our app?
PNFPB Install PWA using share icon

Install our app using add to home screen in browser. In phone/ipad browser, click on share icon in browser and select add to home screen in ios devices or add to dock in macos

PNFPB Install PWA using share icon

Install our app using add to home screen in browser. In phone/ipad browser, click on share icon in browser and select add to home screen in ios devices or add to dock in macos

Progressive Web App (PWA) is installed successfully. It will also work in offline

Push notification permission blocked in browser settings. Reset the notification settings for website/PWA