Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework: public/ vs app/assets/

According to this document, the public/ directory should contain static assets that can be served as they are, while the optional app/assets directory should contain any asset that needs to be processed, for example, by the minify compiler during the build phase.

In case of a SPA (Single Page Application), assets would include JavaScript, CSS, and image files... so does this mean that images files should be stored in public/images while JavaScript and CSS files in app/assets/?

Then, I also need to integrate a third party module that consists of both minified JavaScript libraries and non-minified JavaScript files that need to be customized... How should I manage this? Should I keep standard, already-minified assets in public/ and move customized JavaScript files to app/assets/javascripts/?

like image 851
j3d Avatar asked Sep 26 '14 09:09

j3d


People also ask

Is play a MVC framework?

Play Framework is an open-source web application framework which follows the model–view–controller (MVC) architectural pattern.

Is Play framework asynchronous?

Internally, Play Framework is asynchronous from the bottom up. Play handles every request in an asynchronous, non-blocking way. The default configuration is tuned for asynchronous controllers.

What is play framework in Scala?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

What is activator in play framework?

The activator command can be used to create a new Play application. Activator allows you to select a template that your new application should be based off. For vanilla Play projects, the names of these templates are play-scala for Scala based Play applications, and play-java for Java based Play applications.


1 Answers

Yes, what you describe is correct.

Play combines contents from "managed" and "unmanaged" assets into a single folder during the build process (as mentioned in docs https://www.playframework.com/documentation/2.3.x/AssetsCoffeeScript)

But managed aseets (i.e., app/assets) get compiled - e.g., javascript is run through jshint and then the compiled versions are copied. The unmanaged assets (i.e., public) are taken "as is", with no processing.

Obviously, there is no harm putting your own javascript into the unmanaged public directory, but then you are not taking advantage of the compilation facilities that Play gives you.

For a library which contains customizable files, it depends. I would definitely put the minified files in public, because otherwise you may get compilation errors from jshint. The customized files - depends on the extent of the customization. If it is just small "settings" kind of customization, I may consider putting them together with the other library files just for clarity. But if it's anything that is under active development and involves writing code, I would put it app/assets to get the benefits of jshint syntax checking.

Also, as a side note, you can place your images in app/assets -- they will just be copied without change. But I find that it tends to make things slower by triggering extra unnecessary copies on rebuilds, so having these in the unmanaged directory works better.

like image 54
myrosia Avatar answered Sep 22 '22 10:09

myrosia