Question

is there some built-in tools or plugins to keeping all my page-scripts in one file? I found some topics in play mail list, but all of them has no answer to this question.

Moreover there is google closure compiler somewhere deep, but looks like that nobody except framework developers don't really know about how to make it work.

Any way, it will be pretty if there are some tools which able at least to concatenate all my css together in one file.

Was it helpful?

Solution

Did you read the documentation for Closure? It says:

Any JavaScript file present in 'app/assets' will be parsed by Google Closure compiler, checked for errors and dependencies and minified if activated in the build configuration.

Note: I didn't check it.

OTHER TIPS

I was working on a plugin that does javascript concatenation, minification and gzipping as a replacement for the built in Assets controller, we're using it in our app. Its set up for Play 2.2.1, maybe it would would help you.

https://github.com/edeustace/assets-loader

I think you should use RequireJS integrated in Play framework. It's describe in those following links : - Stackoverflow question - Play framework RequireJS support

I have found a module for the Play 1.x series only that seems to be what we need :

Minimize javascript/css files "press" module

In my Play 2.x project we used views to concatenate multiple javascript file. It diseable minification but was very usefull in term of javascript reuse and files organisation. For css you can use this method too.

A controler named JavascriptRoutes get the script content and put it in the template :

package controllers

import play.api.Play
import play.api.templates.Html

/**
 * Created by dnoz on 30/06/2014.
 */
object JavascriptRoutes {
  def javascriptRouter(scriptName :String): String = {
    val scriptFile = Play.getFile("app/assets/javascripts/" + scriptName)(Play.current)
    val bufferScriptFile = scala.io.Source.fromFile(scriptFile, "utf-8")
    val reformatedScriptContent = bufferScriptFile.mkString
    reformatedScriptContent
  }
}

Here is an example of a part of a script view :

<script type='text/javascript'>
$(function(){
  @Html(JavascriptRoutes.javascriptRouter("backboneClasses/StoredObject/storedObject.model.js"))
  @Html(JavascriptRoutes.javascriptRouter("backboneClasses/Form/form.view.js"))

  //script specific to the view itself:
  var toto = new Object;
  //...
});
</script>

So the script is fully displayed in the final HTML file without minification. If you send the resulted html by using gzip http request it's not mandatory to minified (but always better).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top