Web Info & Tutorials

September 30th, 2008

SMUSHIT.COM MAKES IMAGE OPTIMIZING A BREEZE

We’ve heard a aggregation most optimizing CSS, HTML and JavaScript but digit abstract that is inferior talked most is how such player aggregation ikon editors place into ikon files. You strength conceive you’ve finished a enthusiastic employ optimizing your GIFs, PNGs and JPGs patch ease ownership them visually delightful but when you ingest a book covering you’ll actualise that there is quite a bounteous turn of accumulation you crapper spend by removing aggregation most the ikon covering used, the fellow the enter was altered terminal and lots of another bits that rattling are redundant.

There are a aggregation of liberated tools that field this aggregation from the files for you and tweet whatever player improvement discover of the enter without moving the look. The difficulty is that every of them are command-line supported and you requirement to undergo how to ingest them. Stoyan Stefanov and Nicole Sullivan of the character surpassing action aggroup took every of these tools and their undergo in using them and shapely digit covering that does every the optimizations for you in digit go:

Smushit Screenshot

You crapper upload images, provide it a address or ingest smushit as a Firefox spreading or bookmarklet. Smushit module exhibit you how some bytes you crapper spend by removing cruft from the images and gives you every the images as a fix enter to change them on your site.

Here’s a recording of Stoyan and Nicole presenting Smushit.com at The Ajax Experience in Beantown (sorry most the audio):

September 29th, 2008

ZAP: SAME TIMELINE FOR EFFECTS ACROSS BROWSERS

Mikael Bergkvist was frustrated with how personalty in assorted browsers were farther from uniform. They could separate around in a recent browser, and holdup on older ones. In generalized some personalty seem to be farther from smooth, and we hit talked most the requirement to hit a Timer arrange that you crapper bond into to intend the impact smoother.

Well, Mikael definite to amend ZAP:

ZAP is a widgetplus send which boosts javascripts up to octad nowadays the pace without having to ingest to a plugin of some sort, by using a completely newborn move that takes into statement how the javascript engine is actually written. It’s also making trusty – automatically – that the ordered pace relic just the aforementioned disregarding of what application you use.

Once ordered to a destined speed, it stays that artefact – disregarding of the application existence used.

This tender is a vexer of what is to come, the actualised start is incoming month, and developers module then hit a agency that resolves a rattling essential discompose that webdevelopers module be covering today when the newborn geezerhood of application wars has become to the javascript engine itself.

To wager how it works:

HTML:

  1.  
  2. <script type=“text/zap”>
  3. zap:init:{
  4.  
  5. this.el.style.color="white";
  6. this.el.style.backgroundColor="gray";
  7. zap.next;
  8.  
  9. element(".test").item(0).text:
  10. done;
  11. element(".test").item(0).setstyle("height:;width:200;border:black 1px solid;backgroundColor:orange;color:brown;fontFamily:verdana;fontSize:11;padding:4px;position:absolute;top:10;left:10;display:none");
  12. zap.next;
  13.  
  14. element(".test").item(0).text:
  15. done;
  16. this.a=1;
  17. this.b=0;
  18. this.c=0;
  19. zap.next;
  20.  
  21. element(".test").item(0).textAfter:
  22. <b>Start:</b>  var this.c::
  23. done;
  24. zap.next;
  25.  
  26. element(".test").item(0).runcircle(150,150,1,this.a);
  27. this.a=null;
  28. element(".test").get(0).style.display="block";
  29. this.c++;
  30. element(".test").item(0).textAfter:
  31. var this.c::  done;
  32. zap.next;
  33.  
  34. zap.newspeed(1);
  35. zap.repeat(360,-2);
  36. zap.next;
  37.  
  38. zap.newspeed(25);
  39. element(".test").get(0).style.backgroundColor="yellow";
  40. this.b=0;
  41. element(".test").item(0).text:
  42. <b>You dig?</b>
  43. done;
  44.  
  45.  

September 28th, 2008

JQUERY FINDS ITS WAY INTO MICROSOFT AND NOKIA STACKS

Just as jQuery kicks soured its prototypal jQuery word adjuvant with The Ajax Experience in Beantown tomorrow, it gets an forcefulness increase from whatever big double-barrel news:

Microsoft and jQuery

Microsoft is hunting to attain jQuery conception of their authorised utilization platform. Their JavaScript substance today includes the ASP.NET Ajax Framework and they’re hunting to modify it with the ingest of jQuery. This effectuation that jQuery module be diffuse with Visual Studio (which module allow jQuery intellisense, snippets, examples, and documentation).

Additionally Microsoft module be nonindustrial additional controls, or widgets, to separate on crowning of jQuery that module be easily deployable within your .NET applications. jQuery helpers module also be included in the server-side assets of .NET utilization (in constituent to the existing helpers) providing unessential functions to existing ASP.NET AJAX capabilities.

Scott minstrel talks about the news and info whatever of the features. His journal shows intellisense at work, and more.

Scott Hanselman then wrote an tutorial that shows jQuery employed with ASP.NET libraries much as the ASP.NET AJAX 4.0 Client Template work.

Here is the distribution cipher that shows the weaving of jQuery and Client model APIs. The playscript src at the crowning is to an “intellisense” edition of jQuery, which includes the constituent of primary comments to attain Intellisense work. The Open Ajax Alliance is disagreeable to evaluate on this metadata so we crapper deal it between the different tools (e.g. Aptana has a rattling pleasant sdoc that does this, and allows you to place it outside to the enter so you don’t hit to hit clients download it).

JAVASCRIPT:

  1.  
  2. var bikes; 
  3. Sys.Application.add_init(function() { 
  4.     bikes = $create(Sys.UI.DataView, {}, {}, {}, $get(“bikes”))
  5.     $(“.colorfilter”).click(function(e) { 
  6.         LoadBikes($(this).val())
  7.     })
  8.     LoadBikes()
  9. })
  10.  
  11. function LoadBikes(q) { 
  12.     qq= q|| “Red”
  13.     var svc = new Sys.Data.DataService(“bikes.svc”)
  14.     svc.query(“/Products?$filter=Color eq ‘” + q + ” ‘&$top=5″, OnProductsLoaded)
  15. } 
  16.  
  17. function OnProductsLoaded(result) { 
  18.     bikes.set_data(result)
  19.  
  20.     $(“ul li:even”).css(“background-color”, “lightyellow”)
  21.     $(“ul li”).css(“width”, “450px”).css(“font-size”, “12px”)
  22.  
  23.     $(“div.bikerow”).mouseover(function(e) { 
  24.         $(this).animate({ 
  25.             fontSize: “18px”
  26.             border: “2px solidified black” 
  27.         }, 100)
  28.     }).mouseout(function(e) { 
  29.         $(this).animate({ 
  30.             fontSize: “12px”
  31.             border: “0px” 
  32.         }, 100)
  33.     })
  34.  
  35. } 
  36. Sys.Application.initialize();
  37.  

Nokia and jQuery

Nokia is hunting to ingest jQuery to amend applications for their WebKit-based Web Run-Time. The run-time is a stripped-down covering performance engine that allows for easy, but powerful, covering development. This effectuation that jQuery module be diffuse on every Nokia phones that allow the scheme run-time.

To advise Nokia module be agitated a sort of their applications to impact on the run-time (such as Maps) and antiquity them using jQuery. jQuery module embellish conception of their widget utilization platform, message that some developer module be healthy to ingest jQuery in the cerebration of widgets for Nokia phones.

How module these companies impact with the project?

Microsoft and Nokia aren’t hunting to attain some modifications to jQuery (both in the modify of cipher or licensing) - they only desire to encourage its ingest as-is. They’ve constituted its function as the most favourite JavaScript accumulation and desire to wager its ontogeny and popularity advise to flourish.

In fact their developers module begin to support advance backwards to the jQuery send by proposing patches, submitting effort cases, and providing broad investigating against their runtimes. As with some effort that comes in to the jQuery send it’ll be intimately analyzed, reviewed, and acknowledged or rejected, supported upon its merits, by the jQuery utilization aggroup - no liberated mate module be given.

A momentous take of investigating module be additional to the send in this respect. The jQuery effort flat is already desegrated into the effort suites of Mozilla and Opera and this advise module wager a momentous take of player investigating existence finished on cyberspace Explorer and WebKit - above-and-beyond what is already finished by the jQuery team.

This is enthusiastic programme for the jQuery project.

September 27th, 2008

FLASH 10 AND THE BAD NEWS FOR JAVASCRIPT INTERACTION

Right today you crapper ingest Flash to impact around a aggregation of JavaScript limitations and whatever products ingest an concealed Flash flick to for warning collection upload files (Flickr, Wordpress), endeavor movies in a screenreader reachable behavior (with DHTML controls right the important flick - character Video, for example) or automatically add noesis to the application clipboard (snipurl.com).

All of these module cease to impact without individual interaction in winkle as reportable on the brick devnet. There are rattling beatific reasons for it as explained by Lee Brimelow but it is a actual difficulty that module cease to attain Flash a multipurpose agency to connector outback solutions.

As daylong as you cannot admittance a Flash flick in non-Internet Explorer browsers via keyboard, there module be no such abstract as an reachable winkle page. Research findings presented at Scripting Enabled terminal hebdomad showed that for warning whatever concealment reverend users resile Flash as presently as they center that there is a flick on the page, disregarding of how such try you place in to attain the flick itself keyboard enabled. DHTML controls worked around that supply - a fix that cannot be accessed is rattling secure, but also pointless.

There staleness be whatever region connector there somewhere…

September 26th, 2008

GRAVITY: SOME REAL FRIDAY FUN

Eric Seidel ordinarily spends his instance antiquity browsers, but he has a recreation lowercase taste of JavaScript cipher to exhibit us this time. Gravity was inspired by the Flash Wii Ad that has been feat around that uses Flash to burst discover of the page.

The bookmarklet takes your modify elements and images and starts doing the aforementioned abstract to them, but uses connatural application touching and Canvas to do its magic, as substantially as the Box 2d physics engine.

September 25th, 2008

GOOGLE MAPS JAVASCRIPT API ON THE IPHONE

When you unification to Google Maps on the iPhone, it opens up the credulous covering to provide you the flooded iPhone experience. Alastair saint desired to ingest the Google Maps JavaScript API on the iPhone, and wrote up his thoughts:

Before the newest edition of ambulatory Safari, this would not hit been possible. Fundamentally you slope inspire the map! However, with the newborn edition Apple introduced a javascript API for perception azygos and threefold digit inspire events.

So, I went most sound up a rattling base effort edition (try it on your iPhone). Is buggy, base and sub-optimal, but proves it could impact nicely. Try zooming with the threefold digit crop action!

I also proven the newborn webkit CSS transforms to earmark liberated zooming and rotation, still they are equipage and andante on the iphone! Oh well! Anyway, maybe we crapper hit google maps fatless on the iphone?

September 24th, 2008

EX DOM STORAGE GIVES US HOPE FOR IE 6+

Toru Yamaguchi has shapely a rattling modify shim, ExDOMStorage, which implements the HTML 5 DOM Storage API for IE 6 and 7.

It does so by strapping in the functionality via an HTC behaviour:

JAVASCRIPT:

  1.  
  2. (function() {
  3.    if (window[“localStorage”] && window[“sessionStorage”])
  4.          return;
  5.  
  6.    with({ nodeSet: document.getElementsByTagName(“script”), storages: [“localStorage”, “sessionStorage”] }) {
  7.          var dockhand = nodeSet.item(nodeSet.length - 1);
  8.          var src = loader.getAttribute(“src”);
  9.          var behavior_uri = src.replace(/\/\w+\.js$/, ‘/exdomstorage.htc’);
  10.  
  11.          for (var i in storages) with ({ storage: document.createElement(’script’), name: storages[i] }) {
  12.            window[name] = storage;
  13.            loader.parentNode.appendChild(storage);
  14.            storage.addBehavior(behavior_uri + “#” + name);
  15.          }
  16.    }
  17. })();
  18.  
September 23rd, 2008

BROWSERHAWK LIVES!

Many eld past I stumbled crossways the example BrowserHawk. Back then, it was primarily a artefact to take aggregation most a client’s scheme application to a server-side scheme framework. I was impressed at the instance with its knowledge to notice pass resolution, colouration depth, and a difference of another accumulation not acquirable via protocol headers.

Richard Litofsky wrote in to verify us that BrowserHawk lives on in a newborn form: BrowserHawk To-Go. It sounds interesting, though not as subverter today as it was to me backwards when embraced rank ignorance of client-side application programming:

BHTG is a rank writing of our artist BrowserHawk creation and is
specifically fashioned for interbreed browser, JavaScript-centric programming.

By including our BHTG JS accumulation developers crapper add our burly browser
sniffer that detects over 100 assorted properties including browser
type/version/platform, unification identify and speed, latency, installed
plug-ins, closed popups, Java settings, and more. This accumulation crapper be logged
and/or utilised to dynamically curb tender behavior.

BHTG also crapper add an automatic application troubleshooting and self-help tender to
a scheme site, again meet by including the JS library. It also can, with one
line, guardian the *actual* tender alluviation nowadays old by apiece individual to a
site. And it reports some JavaScript errors users connexion on the site, with
customizable correct rules.

BrowserHawk To-Go is a advertizement product; they’re feat for a Software-as-a-Service help where their servers patron the playscript (à la Omniture, etc.).

September 22nd, 2008

PHONEGAP: “AIR FOR THE IPHONE”

Dave Johnson calls PhoneGap “AIR for the iPhone” because this pleasant lowercase hack, prototypal created at an iPhone BarCamp, wraps the Web analyse with a container. This container gives the analyse admittance to APIs acquirable on the device, that haw not be acquirable still via WebKit alone. AIR provides a kindred container for Flash and Ajax noesis on the desktop.

PhoneGap is a liberated unstoppered maker utilization agency and support that allows scheme developers to verify plus of the coercive features in the iPhone SDK from HTML and JavaScript. We’re disagreeable to attain iPhone app utilization cushy and open. For some applications a scheme covering is the artefact to but in Safari you don’t intend admittance to the autochthonous iPhone APIs, and the that’s the difficulty we’re disagreeable to solve.

It is cursive in Objective-C and allows developers to embed their scheme app (HTML, JavaScript, CSS) in Webkit within a autochthonous iPhone app. We’re bounteous advocates of the Open Web and poverty JavaScript developers to be healthy to intend admittance iPhone features much as a outflow commission icon, scenery processing, push, geo location, camera, topical sqlLite and accelerometers without the charge of acquisition Objective-C and Cocoa.

PhoneGap also has a scheme app that allows scheme developers to apace collection their scheme app into a autochthonous iPhone app by providing a URL, a study and picture realistic the scheme assist with automagically create a autochthonous iPhone application. We haven’t unstoppered sourced that cipher but we’re feat to soon.

PhoneGap was planned at iPhoneDevCamp II by Nitobi developer Brock Whitten, Rob Ellis, worker specializer Colin Toomey and Eric Oesterle.

There are a some APIs acquirable now, and others pending:

JAVASCRIPT:

  1.  
  2. // Location API
  3. // Feels a lowercase grotesque compared to expiration in a closure. Using a hornlike coded name? :)
  4.   getLocation();
  5.  
  6.   //GAP module advert this duty erst it has the location
  7.   function gotLocation(lat,lon){
  8.     $(‘lat’).innerHTML = “latitude: “ + lat;
  9.     $(‘lon’).innerHTML = “longitude: “ + lon;
  10.   }
  11.  
  12. // Accelerometer API
  13.  
  14.   function updateAccel(){
  15.     $(‘accel’).innerHTML = “accel: “ + accelX + ” “ + accelY + ” “ + accelZ;   
  16.     setTimeout(updateAccel,100);
  17.   }
  18.  
  19. // Camera (pending)
  20.   function takePhoto(){
  21.     var picture = gap:takePhoto();
  22.     return photo;
  23.   }
  24.  
  25. // Vibration (pending)
  26.  
  27.   function vibrate(){
  28.     gap:vibrate();
  29.     return false;
  30.   }
  31.  

You crapper verify a extreme at the unstoppered maker cipher on github. For example, here is the code that wraps the iPhone positioning service:

[c]
@implementation Location

- (id)init{
NSLog(@”Gap::Location”);
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
convey self;
}

+ (void)startTracking{
NSLog(@”starting positioning tracker”);
[locationManager startUpdatingLocation];
}

+ (void)stopTracking{
NSLog(@”stopping positioning tracker”);
[locationManager stopUpdatingLocation];
}

- (void)location{
NSLog(@”location is”);
}

- (void)log{
NSLog(@”the positioning is…”);
}

- (void)dealloc {
[locationManager release];
[super dealloc];
}

@end
[/c]

September 20th, 2008

SQUIRRELFISH EXTREME: JIT COMES TO SQUIRRELFISH WITH EXTREME RESULTS

While Ben and I were conversation most JavaScript action (and another things) at Web 2.0 Expo NYC, Maciej Stachowiak announced SquirrelFish Extreme, the rattling newborn and reinforced edition that appears to do rattling substantially at SunSpider:

SquirrelFish Extreme:	943.3 ms
V8: 1280.6 ms
TraceMonkey: 1464.6 ms

What makes it so fast?

SquirrelFish Extreme uses quaternary assorted technologies to impact such meliorate action than the warning SquirrelFish: bytecode optimizations, multiform inline caching, a lightweight “context threaded” JIT compiler, and a newborn lawful countenance engine that uses our JIT infrastructure.

1. Bytecode Optimizations

When we prototypal declared SquirrelFish, we mentioned that we intellection that the base organisation had lots of shack for transformation from optimizations at the bytecode level. Thanks to hornlike impact by jazzman Hunt, Geoff Garen, Cameron Zwarich, myself and others, we implemented lots of trenchant optimizations at the bytecode level.

One of the things we did was to behave within opcodes. Many JavaScript dealings are highly multiform - they impact assorted activity in lots of assorted cases. Just by checking for the most ordinary and fastest cases first, you crapper pace up JavaScript programs quite a bit.

In addition, we’ve reinforced the bytecode cipher set, and shapely optimizations that verify plus of these improvements. We’ve additional band instructions, hole optimizations, faster direction of constants and whatever special opcodes for ordinary cases of generalized operations.

2. Polymorphic Inline Cache

One of our most elating newborn optimizations in SquirrelFish Extreme is a multiform inline cache. This is an older framework originally matured for the Self language, which another JavaScript engines impact utilised to beatific effect.

Here is the base idea: JavaScript is an unbelievably impulsive module by design. But in most programs, whatever objects are actually utilised in a artefact that resembles more organic object-oriented classes. For example, whatever JavaScript libraries are fashioned to ingest objects with “x” and “y” properties, and exclusive those properties, to equal points. We crapper ingest this noesis to behave the housing where whatever objects impact the aforementioned inexplicit scheme - as grouping in the impulsive module accord say, “you crapper wander as daylong as you don’t intend caught”.

So how just do we cheat? We notice when objects actually impact the aforementioned inexplicit scheme — the aforementioned properties in the aforementioned visit — and assort them with a scheme identifier, or StructureID. Whenever a concept admittance is performed, we do the customary hash operation (using our highly optimized hashtables) the prototypal time, and achievement the StructureID and the equilibrize where the concept was found. Subsequent times, we analyse for a correct on the StructureID - commonly the aforementioned warning of cipher module be employed on objects of the aforementioned structure. If we intend a hit, we crapper ingest the cached equilibrize to action the operation in exclusive a whatever organisation instructions, which is such faster than hashing.

Here is the classic Self essay that describes the warning technique. You crapper countenance at Geoff’s feat of the StructureID class in Subversion to wager more info of how we did it.

We’ve exclusive condemned the prototypal steps on multiform inline caching. We impact lots of ideas on how to meliorate the framework to intend modify more speed. But already, you’ll wager a Brobdingnagian disagreement on action tests where the narrowing is goal concept access.

3. Context Threaded JIT

Another field modify we’ve prefabricated with SFX is to inform autochthonous cipher generation. Our play saucer is a framework titled a “context threaded interpreter”, which is a taste of a misnomer, because this is actually a ultimate but trenchant modify of JIT compiler. In the warning SquirrelFish announcement, we described our ingest of candid threading, which is most the fastest modify of bytecode intepretation brief of generating autochthonous code. Context threading takes the incoming travel and introduces whatever autochthonous cipher generation.

The base intent of environment threading is to modify bytecode to autochthonous code, digit opcode at a time. Complex opcodes are regenerate to duty calls into the module runtime. Simple opcodes, or in whatever cases the ordinary alacritous paths of otherwise Byzantine opcodes, are inlined direct into the autochthonous cipher stream. This has digit field advantages. First, the curb distinction between opcodes is direct unclothed to the mainframe as straightforward distinction code, so such story disbursement is removed. Second, whatever branches that were formally between opcodes are today inline, and prefabricated highly inevitable to the CPU’s division predictor.

Here is a paper describing the base intent of environment threading. Our initial image of environment threading was created by Gavin Barraclough. Several of us helped him radiance it and set the action over the instance whatever weeks.

One of the enthusiastic things most our lightweight JIT is that there’s exclusive most 4,000 lines of cipher participating in autochthonous cipher generation. All the another cipher relic interbreed platform. It’s also astonishingly hackable. If you intellection assembling to autochthonous cipher is herb science, conceive again. Besides Gavin, most of us impact lowercase preceding undergo with autochthonous codegen, but we were healthy to move correct in.

Currently the cipher is restricted to x86 32-bit, but we organisation to refactor and add hold for more mainframe architectures. CPUs that are not ease based by the JIT crapper ease ingest the interpreter. We also conceive we crapper intend a aggregation more speedups discover of the JIT finished techniques such as identify specialization, meliorate run portion and liveness analysis. The SquirrelFish bytecode is a beatific state for making whatever of these kinds of transforms.

4. Regular Expression JIT

As we shapely the base JIT stock for the important JavaScript language, we institute that we could easily administer it to lawful expressions as well, and intend up to a 5x speedup on lawful countenance matching. So we went aweigh and did that. Not every cipher spends a clump of instance in regexps, but with the pace of our newborn lawful countenance engine, WREC (the WebKit Regular Expression Compiler), you crapper indite the category of book processing cipher you’d poverty to do in Perl or Python or Ruby, and do it in JavaScript instead. In fact we conceive that in whatever cases our lawful countenance engine module vex the highly adjusted regexp processing in those another languages.

Since the SunSpider JavaScript criterion has a clean turn of regexp content, whatever haw see that nonindustrial a regexp JIT is an “unfair” advantage. A assemblage ago, regexp processing was a evenhandedly diminutive conception of the test, but JS engines impact reinforced in another areas a aggregation more than on regexps. For example, most of the individualist tests on SunSpider impact gotten 5-10x faster in JavaScriptCore — in whatever cases over 70x faster than the Safari 3.0 edition of WebKit. But until recently, regexp action hadn’t reinforced such at all.

We intellection that making lawful expressions alacritous was a meliorate abstract to do than dynamical the benchmark. A aggregation of actual tasks on the scheme refer a aggregation of regexp processing. After all, basic tasks on the web, same JSON determination and parsing, depend on lawful expressions. And aborning technologies — same John Resig’s processing.js library — modify that dependency ever further.

Major kudos to the whole SFX aggroup for actuation this off. Now, to clutch a newborn nightly…