0

I am using webpack plugin "compression-webpack-plugin" which created .js.gz files for app-bundle and vendor-bundle

How can I use gz files in asset precompile so my application.js size can be decreased?

The current Size is 10MB gz file size is of 2 MB

Application.js

//= require vendor-bundle.js.gz
//= require app-bundle.js.gz

If I try to use this i am getting an error

Sprockets::FileNotFound: couldn't find file 'app-bundle.js.gz' with type 'application/javascript'

Configuration

assets.rb

Rails.application.config.assets.paths << Rails.root.join('app', 'assets', 'webpack')

Rails.application.config.assets.precompile += [ "application.js", %w(fullWidthContainer.js IEAlertScript.js carousel.js)) ]

Production.rb

config.assets.js_compressor = :terser
config.assets.css_compressor = :sass
config.assets.compile = false

How can we use js.gz in precompile so file size can be reduced?

Kunal Vashist
  • 2,380
  • 6
  • 30
  • 59
  • I think you're just confused here. Gzip compressions is usually handled on the server level (as in NGinX or Apache)- usually by whatever CDN you're using to serve the assets in production. You don't actually need or want to GZIP the asset files themselves. – max Jun 29 '22 at 22:35
  • Spend your time instead on figuring out how to actually meaningfully reduce the size of your assets files for example by auditng dependencies. – max Jun 29 '22 at 22:37

0 Answers0