« Back to home

JavaScript module patterns and code size

A few days ago I did some code refactoring: File Bytes before Bytes after requestform.js 41491 45884 requestform-min.js 23565 21058 What’s going on here? Well, the code is quite old, and was written using the direct assignment method of global abatement. Now that I’m more comfortable with JavaScript, I rewrote the code to use the revealing module pattern.…

Read more »

The whys of Unobtrusive JavaScript

The HTML standards provide attributes on many elements, enabling you to set them up to call JavaScript when an event occurs. For example, a text field might use the onchange attribute to call some JavaScript to trim whitespace from the beginning and end of the value: <input type="text" id="field1" name="username" onchange="trim(‘field1’);"> However, this method of working has gradually become unpopular. Instead, most now seem to recommend setting up all the events on a page using a JavaScript routine; a practice called unobtrusive JavaScript.…

Read more »