File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes JSP page with js file compression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JSP page with js file compression" Watch "JSP page with js file compression" New topic
Author

JSP page with js file compression

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi,

I have to render the user a jsp page and in the jsp page,there is a javascript called.Now this js file is of 100kb.I want to compress this file while sending it to the user.How can i do it??? I am using Websphere server.

Thanks in advance,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Compress how? Using gzip? Using JavaScript minification?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Dont have much of an idea..about which method to follow.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

As this really doesn't have anything to do with JSP, it's been moved to a more appropriate forum.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

The easiest approach would be to use on of the JavaScript "minimizers". These tools compress the JavaScript by removing whitespace, replacing long variable names, and rearranging the code in various clever ways.

A good example can be found here.

This approach is not without its issues. Primarily, you cannot debug with the compressed JS, so it can be difficult to track down problems in the deployed code.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

I've also heard good things about the YUI JavaScript Compressor, but haven't used it myself yet.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thanks Bear..I will have a look into these..!!!
John Walsh
Greenhorn

Joined: Apr 15, 2011
Posts: 1
A Kumar wrote:Hi,

I have to render the user a jsp page and in the jsp page,there is a javascript called.Now this js file is of 100kb.I want to compress this file while sending it to the user.How can i do it??? I am using Websphere server.

Thanks in advance,


I recommend to use Granule Tag lib the http://code.google.com/p/granule/

It gzip and combine javascripts wrapped by g:compress tag

code sample is:
<pre>
<g:compress>
<script type="text/javascript" src="common.js"/>
<script type="text/javascript" src="closure/goog/base.js"/>
</script>
</g:compress>
...

</pre>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP page with js file compression