How to remove comments and white spaces in html.erb files while deploying to production
System configuration
Rails version:
6.0.0
Ruby version:
2.6.1
How to remove comments and white spaces in html.erb files while deploying to production
System configuration
Rails version:
6.0.0
Ruby version:
2.6.1
Ruby comments (<%# comment %>
) will not be rendered in erb
files.
Not sure about removing whitespaces in .erb
files.
I suggest another approach. To configure gzip
on web-server for example (nginx for example).
This way all your generated HTML responses will be compressed before sending to a browser.
Or you can use HAML
or SLIM
gem to generate HTML instead .erb
You don't.
If you compacted your .erb
templates in production then the line numbers will no longer line up with the files in your "source code". This is essentially the same problem you can face when compacting javascript and there we have source maps that help aliviate the problem.
Its also completely pointless as you can use http compression to compress your responses before they are sent to the client. Whitespace compresses really well.
If you really want to reduce the amount of data your app sends do it by setting up HTTP compression. You can do it on the Rack layer with Rack::Deflate
.
# add to config/application.rb
config.middleware.insert_after ActionDispatch::Static, Rack::Deflater
Or on the HTTP Server layer (NGinx, Apache). Which approach to use depends on the architecture you are deploying to.