Announcement Announcement Module
Collapse
No announcement yet.
Unobtrusive way to combine and compress javascript/css for java/spring/maven applicat Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unobtrusive way to combine and compress javascript/css for java/spring/maven applicat

    I'd like to add some kind of library, or maven plugin, or 'something' to combine and compress my javascript and css source files.

    However, I think this is pretty difficult to do unobtrusively with Java. The Rails people have pretty much solved this problem... it uses the unjoined/uncompressed files for development and then it compresses everything during production. It does this unobtrusively as you don't have to change your html headers or anything like that - it works for both testing and production. This is more or less what I want. Does it even exist in the Java space?

    The last thing I want is to comment and uncomment lines of freemarker/html code for development and production - I want everything to be the same. I guess passing a variable via an Spring Interceptor seems like the only solution to switch between the two versions though. Ideally, I'd want to be able to leave Tomcat running and code my javascript and css, and see my changes instantly - no delays or hickups.

    I also don't want to have to manually run a command to generate the new javascript every time I make a change to the javascript code... or even have some daemon constantly update it (because then it might not be instantaneous when I'm testing, which could be frustration as well).

    At the same time, if I'm going to package up my war for production, I want it to use the joined and compressed files instead.

    Is this even possible? If so, what tool should I be looking at? I know there are quite a few that do some of this, but they've fallen short on the "unobtrusive" aspect.

    I also have at least 50 javascript files I'd like to combine, so solutions that require adding one after the other is going to be tedious. I have a lot more javascript to write too, so I can even imagine 100 or 150 files total. This means including script tags manually in an html file is probably not going to work.

    Thanks
    Last edited by egervari; Nov 21st, 2011, 05:11 PM.

  • #2
    I'm sure there are other ways to accomplish compressing javascript files. but take a look at the build used for spring webflow javascript. It's dojo centric. But I see no reason why that build couldn't be modified to include custom javascript.

    Comment


    • #3
      I'll have a look at it, thanks.

      I hope this isn't just a basic compression program - I know plenty of those exist and my question is more specific than just mere javascript/css minification.

      What I essentially would like is a whole system to manage this, and to manage the differences between development and production environments. Ideally, this is something I think Spring/Spring MVC (and/or maven) should handle - I mean, Rails handles it, so why not Spring?

      I am a long-time spring user - going back all the way to 2001 or 2002 with the original interface21 code. I mostly do Java and Spring.

      I am getting very jealous of Rails. It seems as web applications get more and more complex, Spring MVC is just not providing the level of convenience and richness that it once did. It is falling behind. While it's still possible to build rich web applications using Spring and Spring MVC, it's harder than it is in other competing platforms.

      Now, Rails has it troubles too - make no mistake about this. It is not very reliable. It hard to deploy. Anything that isn't "simple" is a major pain to deal with as the framework has many limitations due to its opinionated nature. There's only so much you can do when working with its opinionated design before you run into trouble. I found that my "common case" that I thought just about everyone would have wanted to do was considered an "exceptional case" - which always baffled me.

      Ruby/Rails is not a very stable platform (I've run into way too many Ruby interpreter crashes and `gem` installation problems that far surpass any jar-hell problems I've run into the past). It is also not as secure of a platform either. It's documentation is abysmal - especially since they change their code's architecture and apis constantly, making 90%+ of the blogs telling you how various things work completely obsolete and will likely waste your time more than it would have taken to program the thing in Java in the first place.

      Having said all of that, the one thing Rails gets right is its WEB framework. It is extremely rich and I think more well-suited to building the WEB portion of the application. I think it sucks at everything else compared to Java/Spring, but sometimes the WEB part is the most complicated, so it might be worth using Rails anyway.

      Anyway, at this point I think Spring/Spring MVC needs to have some better facilities when dealing with complex resources like javascript and css. While I know it's trying to be agnostic about which technologies it supports, these technologies are standard at this point and they need to be better supported. I can't imagine every person wanting to be individually responsible for this when a system could be devised to handle it for everyone

      There's a lot of other areas I think Spring and Spring MVC could throw a bone and help out too (like simpler ajax), but this one is pretty big feature that I think is missing.
      Last edited by egervari; Nov 22nd, 2011, 12:37 PM.

      Comment


      • #4
        I hope this isn't just a basic compression program - I know plenty of those exist and my question is more specific than just mere javascript/css minification.
        It is. But mostly I was thinking of it from a build standpoint. Ie, configure maven to minify/compress the javascript files for profile B, but not profile A.

        Comment

        Working...
        X