Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework 2: JavaScript gets duplicated as a result of minification (google closure compiler)

I have a weird issue related to JavaScript minification, the problem is that when placing JavaScript files such as test1.js, test2.js inside /assets/javascript/test folder and using following options for closure compiler:

val defaultOptions = new CompilerOptions()
    defaultOptions.closurePass = true
    defaultOptions.setProcessCommonJSModules(false)
    defaultOptions.setPrettyPrint(true)
    CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(defaultOptions)

They get minified, but this will cause both test1.min.js and test2.min.js files to share same codes as minified... this will cause some additional JavaScript bugs when files are used within same pages and takes up more disk space.

However, if CompilerOptions is not set, JavaScript compiles properly without duplication but the compilation level is too strict and our JavaScript stops working because it says errors about some things written in those files. Overall, minification process is activated too late to fix all project js files to go through with default compiler options so only option now is to configure it to work in a way which use light minification but without js duplication.. any help on this issue will be highly appreciated!

I'm using Play Framework 2.1.1 with Java project.

like image 231
Mauno Vähä Avatar asked Sep 06 '13 12:09

Mauno Vähä


1 Answers

It seems that this topic has generated some interests, I wan't to point out that I couldn't reproduce this problem after upgrading to play version 2.2.2. So I will be accepting this as a solution because it seems less hacky way to fix it.

like image 163
Mauno Vähä Avatar answered Oct 20 '22 19:10

Mauno Vähä