Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: minify-html

Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: minify-html
Showing posts with label minify-html. Show all posts
Showing posts with label minify-html. Show all posts

JAVA SCRIPT - Minify Your Library

Minify Your Library


Problem

You want to compactly package your code for wider distribution. 

Solution

After you’ve optimized your library code and tested it thoroughly through unit testing, compress it with a JavaScript optimizer.

EXPLAIN

Once you’ve created your library, optimized it for efficiency, and run it through your unit testing, you’re ready to prep your code for production use. One preparation is to compress the JavaScript as much as possible, so the file is small and loads quickly. 

JavaScript compression is handled through minify applications you can find online, such as the well-known and interestingly named UglifyJS. Why Uglify? Because when you compress your JavaScript, it becomes an incomprehensible jumble of densely packed characters. 

To use Uglify, you can either cut and paste your JavaScript into the UglifyJS website page, provide the URL for your JavaScript library, or use the command-line tool. 

The result of running the tool is a mess, like the following:
function timerEvent(){4==xmlhttp.readyState&&populateList(),timer=
setTimeout(timerEvent,3e3)}function populateList(){var a=
"http://burningbird.net/text.txt";xmlhttp.open("GET",a,!0),
xmlhttp.onreadystatechange=processResponse,xmlhttp.send(null)}
function processResponse(){if(4==xmlhttp.readyState&&200==xmlhttp.status)
{var a=document.createElement("li"),
b=document.createTextNode(xmlhttp.responseText);
a.appendChild(b);var c=document.getElementById("update");c.appendChild(a),
c.childNodes.length>10&&c.removeChild(c.firstChild)}else 4==
xmlhttp.readyState&&200!=xmlhttp.status&&console.log(xmlhttp.responseText)}
var xmlhttp=new XMLHttpRequest,timer;window.onload=function()
{populateList(),timerEvent()};


The purpose of a minification tool is to compress the text so it requires less bandwidth and loads faster. Some would say the lack of readability is a perk.