Tool to compress JavaScript file
Moderator: General Moderators
Tool to compress JavaScript file
HI
Version 1.6 of prototypejs is 120KB - uncompressed !
Dont know why the site doesnt offer a compressed version.
Is there good tool out there that compresses (compacts, not zips) a JS file to a smaller size by removing newilnes, comments etc etc ?
Thanks
Version 1.6 of prototypejs is 120KB - uncompressed !
Dont know why the site doesnt offer a compressed version.
Is there good tool out there that compresses (compacts, not zips) a JS file to a smaller size by removing newilnes, comments etc etc ?
Thanks
http://javascriptcompressor.com/
Useful Javascript (already compressed)
* Prototype JavaScript framework 1.5.RC.0 - 21 KB compressed (original was 51 KB)
There are 10 types of people in this world, those who understand binary and those who don't
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
http://dean.edwards.name/packer/
Speaking of which... jQuery is much smaller than prototype (and better, IMO!). Incidentally, jQuery uses packer for the compressed version, which also incidentally is available for download on their site
Speaking of which... jQuery is much smaller than prototype (and better, IMO!). Incidentally, jQuery uses packer for the compressed version, which also incidentally is available for download on their site
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Have to say that I moved from prototype to jquery some time ago. I have found nothing in prototype/scriptaculous that has not been done in jquery and it's plugins with a smaller footprint. It may be simply that scriptaculous if found more readily on google than jquery (that's how I found prototype to begin with). Always remember more popular doesn't necessarily mean better. I could say compare Postgres and Mysql but that would start too long a debate and one that I would be outvoted on purely because everyone seems to use mysql 
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Found this on the Jquery site and JSLint may be of interest.
jquery FAQ wrote:How do I compress my code?
Generally the best way to do it is to use Dean Edwards' Packer (this is the same script that jQuery uses to compress its copy of the library).
An alternative is to use Douglas Crockford's JSMin. This doesn't compress JavaScript code as small, but generally how you write your code matters less. jQuery also provides a pre-minified version of jQuery for your convenience.
If compressing your JavaScript breaks it, try running the code through JSLint. This will detect minor errors that can cause packed JavaScript to fail while the unpacked version works fine.
After recently first-time using jQuery today, and a previous user of scriptaculous.. the cross-browser compatibility issues are resolved very well in jQuery. Not so much in scriptaculous.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Odd, Im now using jQuery instead !!!
There are not enough docs/tutorials/examples on prototype. The best I could find was this.
So far jQuery is enough for my requirements - its 50KB compared to the 120KB prototype (readable versions).
But jQuery's docs is neat and can learn faster. I probably will check out prototype another time when more sophisticated requirements arise.
Btw,
How do I know in jQuery if the ajax object isnt false or not ? Im not looking for the :error function.
I need to know before doing $.ajax({ ... })
There are not enough docs/tutorials/examples on prototype. The best I could find was this.
So far jQuery is enough for my requirements - its 50KB compared to the 120KB prototype (readable versions).
But jQuery's docs is neat and can learn faster. I probably will check out prototype another time when more sophisticated requirements arise.
Btw,
Code: Select all
var xhr = getAJAXObject(); // XMLHttpRequest Variable
function PostCommment()
{
if (!xhr) document.getElementById("Form1").submit(); // AJAX error : switch to <form> submit
// To do AJAX submit using $.ajax or whatever
return false; // To stop the <form> being submitted, since its done via AJAX
}
Code: Select all
function getAJAXObject()
{
var xhr = false;
if (window.XMLHttpRequest) // native XMLHttpRequest object
{
try { xhr = new XMLHttpRequest(); }
catch(e) { xhr = false; }
}
else if (window.ActiveXObject) // IE/Windows ActiveX version
{
try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e)
{
try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e) { xhr = false; }
}
}
return xhr;
}
I need to know before doing $.ajax({ ... })
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
How can I know if $.ajax() has failed initializing ? Not talking abt error msgs after AJAX is done - Im talking abt AJAX not being able to initialize in the first place.
Btw, Checkout the source code of http://code.google.com/
Btw, Checkout the source code of http://code.google.com/
Wow !<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jq ... "></script>