The play documentation says that « By default, [the Assets] controller provides caching, ETag, gzip compression and JavaScript minification support. »
How can I set up play to minify the javascripts files ? It's not done in the default setting either in dev or prod mod, and the doc doesn't explain it.
Thank you.
To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.
To minify JS, CSS and HTML files, comments and extra spaces need to be removed, as well as crunch variable names so as to minimize code and reduce file size. The minified file version provides the same functionality while reducing the bandwidth of network requests.
It is important to minify your CSS and minimise JavaScript files so they can load faster on your web pages. There are many reasons why you should minify your CSS and JavaScript: Reduce file size: The more code there is in a file, the larger it will be. Minified code is usually much smaller than the original version.
How Minification Works. Minification works by analyzing and rewriting the text-based parts of a website to reduce its overall file size. Minification extends to scripts, style sheets, and other components that the web browser uses to render the site. Minification is performed on the web server before a response is sent ...
Make sure your javascript ressources are located in your /app/assets/javascript
folder (so you will benefit from Google Closure Compiler), and then, you just have to name your js file using whatevername**.min**.js
Example in a view:
<script src="@controllers.Assets.at("public", "javascripts/whatevername.min.js")" type="text/javascript"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With