What's the best practice for including CSS and javascript files in a java web project?
I've recently started on a new google app engine project that uses RestEasy for MVC and Grad开发者_高级运维le for our build process. Now I'm at a point where I want to include SASS, javascript, and closure template files but I'm unsure about how I should do this. Ideally I'd like to satisfy the following requirements:
- The files should live in their own source directory. eg src/main/javascript, src/main/sass.
- When deploying, the javascript files should be minified.
- When developing, the closure templates and sass files should be watched for changes and hot-swapped into the running environment.
- The closure templates should be accessible by the client and server. (That way rendering can happen on either end)
What do you think is the best way to accomplish all of this? Thanks for your time.
I'm placing it into
src/main/webapp/js
andsrc/main/webapp/sass
(compiled tosrc/main/webapp/css
It's pretty standard and goes well with all maven pluginThere is
yuicompressor-maven-plugin
, it can compress js and cssIf you're using Compass for SASS, then it can watch and recompile out of box (
-watch
option). BTW, it's complicated to make hot-swapping. Instead of it I'm using local nginx in front of my gae app, it proxying all non-static request to original jetty (used by gae plugin), but serves all static files (like js, images, css) directly fromsrc/main/webapp
. It's pretty easy to configure nginx for that scenarioIt's the problem, and can't find any good solution for that :( So i'm trying to render this part only at client side (by using jquery-tmpl), passing all data as javascript/json, directly inside my jsp's
精彩评论