Wednesday, November 12, 2008JavaScript Libraries
Speaking of implementing paging (and caching and a lot of other things on my todo list), I have been really busy behind the scenes fixing bugs and making other improvements to both this blog and loadaverageZero in general. Some of them my visitors may have noticed, some may not. But things are definitely on the upswing around here since health has improved. One thing that really has me puzzled is what to do with this blog. I'm running a rather old, and hacked to pieces, version of Serendipity. I don't want to let go of the design, which I spent a lot of time on, yet on the same token it bothers me that my only recourse to block spammers and other miscreants was to disable comments and trackbacks. I'm not a big fan of Captchas, I would prefer to go the OpenID route. Anyway, I'm starved and I haven't been to the diner for some good old eggs and bacon in ages... Thursday, November 6, 2008Google Code: Ajax Libraries API
Too Late AgainYou guessed it, he publishes a follow-up article. The reason I went looking for it in the first place, or rather found it to be the best write-up on the topic, was not so much the how, but the why of using this technique. But he kind of missed the point. Sure, he explains the ins and outs and a bit of the history of sprites, but for my money the single best reason to consider using the technique is a huge reduction in the number of HTTP requests you serve up when storing a bunch of similar iconic images from one master file. Better still, once the browser downloads the aggregate file and caches it, it's a simple matter of some integer offset math to display only that portion you need as a background image in your documents. Sprites in a NutshellBasically, the technique involves creating one or more fixed-sized, block-level elements with ids or classes to be used as selectors in your stylesheet, set the CSS Sprites ReduxThe latest version of the article takes the technique a step further by introducing some animation effects via John Resig's outstanding jQuery JavaScript library. But Dave misses the original point again, which I found ironic after he warns his audience that using jQuery imparts a certain overhead when downloading the library for the first time. Ajax Libraries API
google.load()Personally, I don't understand the advantage of using the google.load() method unless your project involves using their Maps, Search, or Ajax Feed APIs. Why not just load the library and start using jQuery (or whatever) like you normally would?
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
// when the DOM is ready
$(function() {
// fire away
$('#selector').method({
// ...
});
// ...
});
</script>
Related Reading
Posted by Douglas Clifton
in CSS, JavaScript
at
06:00
tags: ajax, api, cache, cdn, css, framework, google, http, javascript, jquery, open-source, performance, programming
Wednesday, November 5, 2008JavaScript on Crack
Evaluation ParametersBefore I get into what's on the horizon, I took the time to evaluate the relative performance of JavaScript in four current browsers. I'll be using the WebKit SunSpider JavaScript benchmarking tool on my Dell XP Pro laptop with the latest Service Packs installed. Internet Explorer is not in the mix because, first of all I can't stand the browser, but mostly because it would likely be crushed by the other competitors—listed below by product, version, vendor, and JavaScript engine:
To level the playing field, each test was performed after a fresh restart with no other foreground applications running. Of the four, Firefox was the most heavily loaded, at least in terms of the number of extensions/plugins installed. I'm not sure if that would have an impact on the results or not. In all cases there were no other tabs open to skew the results (Google mail leaps to mind). Firefox
Safari
Chrome
Opera
FindingsRanked from fastest to slowest overall: Now I'm not a statistician, but Safari and Firefox yielded very similar results in the middle ground, while Chrome was the clear winner with Opera at the bottom (surprising, given the browser's reputation for performance). SunSpider has a nice feature that allows you to compare two result sets. The difference from fastest to slowest was a staggering 279% speed increase in Chrome over Opera. Of course a lot depends on what you're using JavaScript for, hence the breakdown into categories and different operations within those categories. If you enjoy pouring over raw data, by all means have at it. On the HorizonOver the past several months we've seen all manner of announcements and articles about JavaScript performance improvements and what to expect when this research and development makes its way into the mainstream. We've learned about trace trees, JIT compilers, direct-threaded, bytecode optimizers, and so on. Mozilla, for example, plans to roll out it's TraceMonkey engine with the release of Firefox 3.1. For the impatient, you can grab a copy of the 3.1 nightly builds and enable TraceMonkey now if you want to play with it or do your own testing. One can only speculate on how Google and Opera will respond to these latest developments. Related ReadingSaturday, October 25, 2008Firefox Power Tools For Web Developers: FireBug
The latest version of FireBug was released September 12th, 2008. What in the hell is a FireBug?I won't get into entomology—which ironically in Greek means "that which is cut in pieces"—although there really is such a thing as a firebug. The extension, on the other hand, is designed to make the Web developer's job a whole lot more productive. With it you can inspect and debug your markup, stylesheets, JavaScript, and even keep an eye on asynchronous XHR object calls back to your server. Unlike the DOM Inspector, FireBug normally runs in a horizontal console (although you can open it in a separate browser window) underneath the document's rendered view. A statusbar icon indicates if there are any problems with the current page, which can indicate any number of conditions including errors, warnings and results from:
and even problems encountered from remote domains—which can be the source of massive numbers of errors (I'll leave it to Joe to name names). Thankfully you can suppress these messages, or disable FireBug entirely for certain domains, through the options menu. Almost every object in the FireBug interface is actually a hyperlink. Elements in the source view can be expanded or collapsed and your current XPath is displayed as you explore the document structure. Like the browser itself, views are toggled through a tabbed interface, which include Console, HTML, CSS, Script, DOM, and Net. Each tab has one or more sub-functions associated with that feature. By using FireBug, you will quickly learn just how much is going on behind the scenes of even the simplest Web page. Power ToolsForget about using alert() to test or debug your scripts. By adding console object logging to your code you can pinpoint exactly what is going on, and even restrict messages according to different levels of severity including: informative, debug, warnings, or errors. The console object also allows you to make assertions to more deeply test your code as well as performing stack traces, time sections of code, and log the number of times a function is called and has been executed. All of the console logging methods can format strings using patterns similar to the C stdio printf() family of functions. Command Line FunctionsFor command line junkies like me, console mode gives you access to a wealth of query and history/editing features you're probably already familiar with. Even more powerful are the following predefined shorthand functions:
>>> inspect(document) is a good place to get started. CSS Quick SearchWhile in Inspect mode, you can use the quick search box to locate any element by entering a CSS selector. FireBug will display all matching elements in the console view, which you can then expand to view more details or switch tabs to explore the stylesheet that defines the rules for each element, the computed propeties and layout/display attributes, JavaScript events that are attached to the element, and even the gory details of DOM for the selected item. You can also use quick search to match JavaScript events. In the future, Joe plans on adding XPath search as well as plain text. For those in a hurry, you can try the getElementsBySelector() JavaScript function, which uses the Firefox XPath API to translate CSS selectors to XPath making them a lot faster than searching the DOM directly. FireBug 1.2Some of this material is a bit dated. For the latest on FireBug, visit the new Get FireBug Web site and in particular the "Learn more" feature links on the home page and the documentation section. Saturday, September 27, 2008I'm Back...
Wow, talk about a hiatus. Looking down at the previous post it's been over a year since the last time my shadow has darkened this doorway. Below are a few recent items of interest regarding development and the Web in general. To me at least. But who am I kidding? I must be the only person left who actually still reads this blog.
Stay tuned, I may just be back sooner than 12 months. In fact, you can count on it.
Posted by Douglas Clifton
in Blog, Web, Browsers, Commentary, JavaScript
at
19:28
tags: apple, beta, blog, browser, commentary, framework, google, history, javascript, mozilla, open-source, search, user-interface, web, webkit
Monday, January 29, 2007Power Tools for JavaScript Developers
JavaScript development just keeps getting more efficient and powerful! Thursday, January 11, 2007PHP/Ajax Integration
Jonathan Modell was tonight's presenter. A DC local, recently returning from a 10 year stint in Colorado (my home state, or more accurately I was born in Durango and then lived in Boulder for a year), Jon has extensive experience in many aspects of Web development. His presentation focused on how he learned to integrate Ajax technology within a core PHP system. Obviously this is a hot topic, if somewhat too hot in my opinion. In a nutshell, Ajax allows you to create an HTTP request back to a server-side script, and then dynamically insert the results into your page via the DOM—all without having to POST or GET a new page (something most PHP programmers are well versed in). Web-based applications that quietly introduced this technique are most famously associated with Google. First was "suggest" a sort of search as you type, and then Gmail and many others that began to reinvent how Web pages could improve interactivity. In truth, it was Microsoft (circa 2000) who first implemented the XMLHttpRequest (XHR) object in their version of JavaScript (jscript). Later browsers (Firefox, Safari, et al.) followed suit. As the function implies, the traditional payload of a server-side script called by an XHR request is XML. I know of very few people that continue to do this. By far the simplest method of dynamically insterting results into your page is to use a element with a unique id, initially hidden via CSS, then grab the data returned as normal markup (for instance a set of unordered list elements), then use innerHTML to update the DOM, and finally "unhide" the element (typically a <div>). This technique is sometimes referred to as AHAH. JSON is another lightweight technique for returning data to the requestor. It's basically serialized JavaScript in the form of name/value pairs that you eval() on the client-side for parsing and insertion into your page. In addition to JSON, the Yahoo! Developer Network set of Web services are able to return serialized PHP. Although not as applicable to an Ajax implementation, it is none-the-less an interesting method worth investigating. If there is such a beast as a JavaScript unserialize PHP function or class out there, by all means drop me a comment. For PHP developers interested in available packages for encoding and decoding JSON data, visit this comparison of PHP libraries. As of PHP version 5.2.0, JSON support is native. In the early stages of his presentation, Jon confessed to having tested many of the Ajax JavaScript libraries that are floating around out there, and then spoke highly of his choice to use Sam Stephenson's Prototype. He is not alone, not by a long shot. There are a number of frameworks that are built on top of Prototype: RoR, Rico, and "effects" libraries that include script.aculo.us and moo.fx. PHP frameworks with built-in Ajax support include CakePHP and ModX. If you are doing this sort of development work, I cannot emphasize enough how much Joe Hewitt's fantastic FireBug Firefox extension will save you hours of headaches. To conclude his presentation, Jon demoed a social networking application that displays a calendar of events and the members who are attending, locations, dates, and so on. I came away with the feeling that traditionalists in the audience were impressed how the page would update without the need to refresh it. But keep in mind that is the nature of asynchronous requests. There is nothing particularly new going on here, these are normal HTTP requests, they just happen to occur in the background via JavaScript and a little DOM magic to alter the page on the fly. Wednesday, April 12, 2006New Goodies From Yahoo! Maps Beta
For developers, several of the Map APIs have also been upgraded to Version 3. These include: Why it's taking so long for a killer mashup that integrates geotagged Flickr photos with Yahoo! Maps Beta is a mystery to me, although I can guess who is working on it. To stay up to date on the latest development news, join the Yahoo! Maps Developer Community. There is never any need to get lost. Wednesday, March 29, 2006Exposing JavaScript
Another prevalent thread running through the comments is the concept of learning by observation, or what I like to call "how'd they do that?" In order to understand a technique, one of the best methods is to study source code. This is easy enough to do with any browser, and Firefox has some extensions that make it even easier. On my own Web site I try to expose as much as possible, including the markup, PHP source code, I also list my CSS and JavaScript files in the sitemap, and so on. These are just niceties, because other than code originating on the server-side (PHP for example), anything delivered to the user-agent is viewable in source form. Unless you're in the obfuscation camp, which I'm not here to discuss (shame on you if you are). By now you may have heard of Ajax, and the booming trend in dynamic or DOM or client-side scripting that goes along with it. In other words, JavaScript is red-hot right now. If you're just getting into scripting, then this is a damn fine time to be learning by studying the code that drives all this stuff. It's also a fine time to be learning JavaScript because its reputation as a toy language with many poor examples is quickly being replaced by a new-found respect and clean, structured code. As far as JavaScript code goes, there are a couple of different sources you're likely to run into. Embedded JavaScript can be found right in the markup. This is still almost as common as it is a bad practice. So there you are, back to viewing the page markup. Often this practice is made even worse by code that is disorganized and dispersed all over the place. There is also inline JavaScript, most often used to fire on certain events such as onclick, but I'm not going to get into that here. Likewise for so-called "javascript:" protocol URLs, such as those used by bookmarklets. A better solution is to use the src attribute of the <script> element to include external libraries of code. Some developers claim this can cause the page to load more slowly since it involves an extra HTTP GET request for each included JavaScript source file. In my opinion modularity, code maintenance and browser caching of the external scripts easily trumps these concerns. So once you land on that page with the fancy JavaScript effects, what is the best way to study the techniques being used? One method is to open the source of the page, locate the code embedded in it, or in the case of external source, copy the URL to the file and make a separate request with your browser. Using this rather tedious method for external code with Firefox and most other browsers will result in the code being displayed in a window as plain text, although IE has a nasty habit of prompting you to download the file rather than simply displaying it. A more elegant solution is to use JSView, a Firefox extension which will open up separate view-source windows for any or all external JavaScript files referenced by the current page (it will do the same thing for external CSS). I find this method acceptable if I only want to look at a particular file, and it sure beats hunting through the markup, copying (and possibly having to modify "../.." paths) then pasting the URL into the address bar of a another tab or window so you can continue to view and test the rendered page. But this method only works for external source code. Some pages use a mixture of external files and embedded code. In these cases, the all-powerful Web Developer extension really shines. From the Information menu, select "View Javascript" and the extension opens a new tab with all the JavaScript from the current page concatenated into one view. Code from external files are labeled as such with links to the files, and embedded JavaScript is labeled as "Inline Script" referencing the document that defined it. The code appears in source-order, or in other words in exactly the same sequence as it is appears in the markup. But source order is not important to the JavaScript interpreter embedded in your Web browser. It simply builds a collection of objects after receiving and parsing each form of source code, and then waits for some event to fire that will trigger the intended behavior. If you think in these terms, which I recommend, then Steve Chipman's JavaScript Object Tree favelet/bookmarket is the way to go. To use it, simply drag a copy of the link to your bookmarks toolbar, then on the page you want to study click the link. A new <div> element appears overlaying the top portion of the document and in it you will find a collapsed tree-view of every object type defined by that page. Object types include functions, objects (arrays, dates, etc.), strings, numbers, and so on. To expand an object type into a list of its members, just click on it. To view the value of an object, which in the case of a function is its source code, just click on the item by name. You can easily collapse parts of the tree in the same manner. Another really handy favelet is Shaun Inman's View Rendered Source, which also overlays the current document with source code, but not JavaScript code. Rather, it displays the browser's internal view of the markup after any changes are made to the DOM. For example, if a script is using Ajax to insert new elements into the document tree and you want to observe the results, then the script will give you a before and after snapshot of the markup. Remember that observation and studying working examples are powerful ways to learn how Web software is built, and a great way to improve your skills. Whether you are a new or a seasoned JavaScript developer, if you plan on studying code in the wild then Firefox and its many extensions, and any number of other tools (I'm just scratching the surface here) are the way to go. Tuesday, March 7, 2006Ajax in a Nutshell
And this leads to my point, something I plan on asking as many designers as I can corner at SXSW—in this day of Rich Internet/Web applications and Ajax (I really hate to mention Web 2.0), do you see the line between designer and programmer blurring a bit more? If you're not able to make it to the convention, feel free to post your viewpoints here, regardless of whether your area of expertise is design or code.
Posted by Douglas Clifton
in Design, JavaScript
at
19:01
| Comments (6)
tags: ajax, app, design, developer, dom, javascript, markup, programming, ria, sxsw, user-interface, web 2.0, xmlhttprequest
(Page 1 of 2, totalling 15 entries)
» next page
|
Calendar
ArchivesQuicksearchSyndicate blogZerolinkZeroCategoriesTagsAdmin |
|||||||||||||||||||||||||||||||||||||||||||||||||














Newsvine Technology
