New Features Coming in Browsers (RIT '09)
Upcoming SlideShare
Loading in...5

New Features Coming in Browsers (RIT '09)



Talk I gave in May 2009 at RIT.

Talk I gave in May 2009 at RIT.



Total Views
Slideshare-icon Views on SlideShare
Embed Views



1 Embed 4 4



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    New Features Coming in Browsers (RIT '09) New Features Coming in Browsers (RIT '09) Presentation Transcript

    • New Features Coming in Browsers John Resig -
    • About Me✦ Work for the Mozilla Corporation (Firefox!) ✦ Do a lot of JavaScript work ✦ is my performance test suite ✦ Tests the performance of JavaScript engines ✦ Tests the performance of browser DOM ✦ is an application for distributed JavaScript testing.✦ Creator of the jQuery JavaScript Library ✦ ✦ Used by Microsoft, Google, Adobe, Nokia, IBM, Intel, CBS News, NBC, etc.
    • Upcoming Browsers✦ The browsers: ✦ Firefox 3.5 ✦ Safari 4 ✦ Internet Explorer 9 (?) ✦ Opera 10 ✦ Google Chrome 2✦ Defining characteristics: ✦ Better performance ✦ Advanced JavaScript engines
    • Firefox 3.5✦ Set to be released Summer 2009✦ Goals: ✦ Performance improvements ✦ Video and Audio tags ✦ Private browsing✦ Beta 4 just released✦
    • Safari 4✦ Released in conjunction with OS X 10.6✦ Features: ✦ Performance improvements ✦ Desktop Apps ✦ ACID 3 compliance ✦ Revamped dev tools✦ Preview seeded to developers✦
    • Internet Explorer 8✦ Released early 2009✦ Features: ✦ Backwards compatibility with IE 7 ✦ Web Clips (trim out a part of a page and place on desktop) ✦ Process per tab✦ windows/internet-explorer/ beta/readiness/new-features.aspx✦ No details on IE 9, yet.
    • Opera 10✦ Unspecified release schedule (2009?)✦ Features: ✦ ACID 3 compliance ✦ Video and Audio tags✦ Opera 9.6 recently released✦
    • Google Chrome✦ Chrome 1.0 September 2008✦ Features: ✦ Private browsing ✦ Process per tab✦ Chrome 2.0 upcoming✦
    • Process Per Tab✦ Most browsers have a single process ✦ Share memory, resources ✦ Pages rendered using threads✦ IE 8 and Chrome split tabs into individual processes✦ What does this change? ✦ Pages can do more processing ✦ (Not block the UI or other tabs) ✦ Tabs consume more memory
    • Process Per Tab✦ Examples of changes, in Chrome.✦ Timer speed is what you set it to. ✦ Browsers cap the speed to 10ms. ✦ setInterval(fn, 1);✦ Can do more non-stop processing, without warning: while (true) {}✦ Chrome has a process manager (like the OS process manager - see CPU, Memory)
    • JavaScript Engines✦ New wave of engines: ✦ Firefox: TraceMonkey ✦ Safari: SquirrelFish (Extreme) ✦ Chrome: V8✦ Continually leap-frogging each other
    • Common Areas✦ Virtual Machines ✦ Optimized to run a JavaScript-specific bytecode✦ Shaping ✦ Determine if two objects are similar ✦ Optimize behavior based upon that ✦ “Walks like a duck, quacks like a duck” ✦ if ( obj.walks && obj.quacks ) {}
    • Engine Layers JavaScript Code JavaScript Engine (C++) Virtual Bytecode Machine Machine Code
    • Bytecode✦ Specific low-level commands✦ Written in machine code✦ a + b;✦ PLUS( a, b ) { IF ISSTRING(a) OR ISSTRING(b) { return CONCAT( a, b ); } ELSE { return ADD( a, b ); } }
    • Shaping✦ Simple JavaScript code: obj.method()✦ GETPROP( obj, name ) { IF ISOBJECT(obj) { IF HASPROP(obj, name) return PROP(obj, name); ELSE return PROTO(obj, name) } ELSE { ERROR } }
    • Shaping (cont.)✦ EXEC( prop ) { IF ISFN( prop ) { RUN( prop ) } ELSE { ERROR } }✦ After shaping: RUN( PROP( obj, name ) )✦ Optimized Bytecode
    • TraceMonkey✦ Firefox uses an engine called SpiderMonkey (written in C)✦ Tracing technology layered on for Firefox 3.5 (dubbed ‘TraceMonkey’)✦ Hyper-optimizes repeating patterns into bytecode✦
    • Tracing✦ for ( var i = 0; i < 1000; i++ ) { var foo = stuff[i][0]; foo = “more stuff ” + someFn( foo ); } function someFn( foo ) { return foo.substr(1); }✦ Loop is costly ✦ ISNUM(i) ✦ ADD(i, 1) ✦ COMPARE( i, 1000 )
    • Function Inlining✦ for ( var i = 0; i < 1000; i++ ) { var foo = stuff[i][0]; foo = “more stuff ” + foo.substr(1); }
    • SquirrelFish✦ Just-in-time compilation for JavaScript✦ Compiles a bytecode for common functionality✦ Specialties: ✦ Bytecodes for regular expressions (super- fast)✦ javascript-performance
    • Chrome V8✦ Makes extensive use of shaping (fast property lookups)✦ Hyper-optimized function calls and recursion✦ Dynamic machine code generation✦
    • Measuring Speed✦ SunSpider ✦ Released by the WebKit team last fall ✦ Focuses completely on JavaScript✦ Dromaeo ✦ Released by Mozilla this spring ✦ Mix of JavaScript and DOM✦ V8 Benchmark ✦ Released by Chrome team last month ✦ Lots of recursion testing✦ Quality:
    • Network
    • Network✦ Steve Souders’ UA tool:✦ Also see: YSlow
    • Parallel Scripts✦ Download scripts simultaneously✦ Even though they must execute in order✦ <script defer> ✦ From Internet Explorer ✦ Just landed for Firefox 3.5 ✦ In Opera as well ✦ Replacement for JavaScript-based loading
    • Link Prefetching✦ <link rel=”prefetch” href=”someimg.png”/>✦ Pre-load resources for later use ✦ (images, stylesheets)✦ Currently only in Firefox✦ Replacement for JavaScript preloading
    • Communication
    • postMessage✦ A secure way to pass string messages amongst multiple frames and windows✦ Implemented in all browsers (in some capacity). addEventListener(“message”,...) postMessage(“hi!”)
    • postMessage✦ Sending a message:✦ iframe.postMessage(“test”, “”);✦ Receiving a Message:✦ window.addEventListener(”message”, function(e){ if (e.origin !== ““) return; alert( ); }, false);
    • Cross-Domain XHR✦ Landed in Firefox 3.5, support in IE 8✦ Add a header to your content: Access-Control-Allow-Origin: *✦ XMLHttpRequest can now pull it in, even across domains✦ HTTP_Access_Control
    • DOM Navigation
    • Class Name✦ New method: getElementsByClassName✦ Works just like: getElementsByTagName✦ Fast way of finding elements by their class name(s): <div class=”person sidebar”></div>✦ document.getElementsByClassName(“sidebar”)✦ Safari 3.1, Firefox 3.0, Opera 9.6✦ Drop-in replacement for existing queries
    • Speed Results
    • Selectors API✦ querySelectorAll✦ Use CSS selectors to find DOM elements✦ document.querySelectorAll(“#foo > p”)✦ Good cross-browser support ✦ IE 8, Safari 3, FF 3.5, Opera 10✦ Drop-in replacement for JavaScript libraries.
    • Speed Results
    • Traversal API✦ W3C Specification✦ Implemented in Firefox 3.5✦ Some methods: ✦ .nextElementSibling ✦ .previousElementSibling ✦ .firstElementChild ✦ .lastElementChild nextElementSibling <div> Text <div>✦ Related: previousElementSibling ✦ .children (All browsers)
    • Styling and Effects✦ Lots of commons styling effects✦ Can be replaced and simplified by the browser✦ Drastically simplify pages and improve their performance✦ New: The ability to apply SVG transforms and effects using CSS.
    • Rounded Corners✦ CSS 3 specification✦ Implemented in Safari, Firefox, Opera ✦ -moz-border-radius: 5px; ✦ -webkit-border-radius: 5px;✦ Can replace clumsy, slow, old methods.
    • Shadows✦ Box Shadows ✦ Shadow behind a div ✦ -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.5)✦ Text Shadows ✦ Shadow behind some text ✦ text-shadow: -1px -1px #666, 1px 1px #FFF;✦ Implemented in WebKit, Firefox✦ Can replace clumsy, slow, old methods.
    • Example Shadows✦ Demos: shadow.html
    • Custom Fonts✦ Load in custom fonts✦ Can load TrueType fonts✦ Implemented in Safari and Firefox✦ Demo: blok.html✦ Can replace using Flash-based fonts.
    • Transforms and Animations✦ Transforms allow you to rotate, scale, and offset an element ✦ -webkit-transform: rotate(30deg);✦ Animations allow you to morph an element using nothing but CSS ✦ -webkit-transition: all 1s ease-in-out;✦ Implemented in WebKit and Firefox✦ Demo: css-animation/✦ Can replace JS animations, today.
    • Data
    • SQL Storage✦ Part of HTML 5 - a full client-side SQL database (SQLite)✦ Implemented in WebKit✦ var database = openDatabase(”db”, “1.0”); database.executeSql(”SELECT * FROM test”, function(result1) { // do something with the results database.executeSql(”DELETE FROM test WHERE 1=1;”); });
    • Native JSON✦ JSON is a format for transferring data ✦ (Uses JavaScript syntax to achieve this.) ✦ Has been slow and a little hacky.✦ Browser now have native support in Firefox 3.5 and IE 8✦ Drop-in usable, today ✦ JSON.encode(object) ✦ JSON.decode(string)
    • Performance✦ Encoding:✦ Decoding:
    • Canvas✦ Proposed and first implemented by Apple in WebKit✦ A 2d drawing layer ✦ With possibilities for future expansion✦ Embedded in web pages (looks and behaves like an img element)✦ Works in all browsers (IE with ExCanvas)✦ Offload rendering to client✦ Better user interaction
    • Shapes and Paths✦ NOT vectors (unlike SVG)✦ Rectangles✦ Arcs✦ Lines✦ Curves✦ Charts:
    • Fill and Stroke✦ All can be styled (similar to CSS)✦ Stroke styles the path (or outline)✦ Fill is the color of the interior✦ Sparklines:
    • Canvas Embedding✦ Canvases can consume: ✦ Images ✦ Other Canvases✦ Will be able to consume (Firefox 3.5, Safari 4): ✦ Video✦ In an extension: ✦ Web Pages
    • JavaScript Threads✦ JavaScript has always been single-threaded✦ Limited to working linearly✦ New HTML 5 Web Workers✦ Spawn JavaScript threads✦ Run complicated work in the background ✦ Doesn’t block the browser!✦ Drop-in usable, huge quality boost.
    • A Simple Worker✦ var myWorker = new Worker(’my_worker.js’);   myWorker.onmessage = function(event) {   alert(”Called back by the worker!n”);   };  
    • Questions?✦ John Resig✦ Mozilla will be at the Fall Career Fair