Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate javascript minification?

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.

like image 420
Raphaël Lemaire Avatar asked Jun 22 '12 16:06

Raphaël Lemaire


People also ask

How do you do minification in JavaScript?

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.

What is JS and CSS minification?

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.

Should you minify JavaScript?

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 do JS minify cause work?

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 ...


1 Answers

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>
like image 120
ndeverge Avatar answered Oct 13 '22 10:10

ndeverge