Posts tagged Fast
A Quick Intro: Canvas in IE9
1Yesterday, with the release of Internet Explorer 9 Platform Preview 3, the engineering team announced support for hardware accelerated <canvas>! The <canvas> element is a part of the HTML5 Standards specification and allows for dynamic scriptable rendering of 2D graphics. To use it, you put a simple <canvas> element in your HTML, which defines the drawing area, then through JavaScript, you can get the 2d context and begin dynamically drawing within that region.
Much like SVG, you can draw on the page using basic shapes, but you can also easily include rasterized images, videos and other objects. But unlike SVG, when you draw on the page, the browser doesn’t remember any of the “drawings”. With SVG, the “drawings” just become elements in the DOM and you can script them, change them, basically treat them like any other element. Canvas on the other hand, doesn’t remember the state of the “drawings” so you can’t change them as easily.
Quick Code Sample
<canvas id="myCanvas" width="200" height="200"
style="border: 1px solid black;">
Your browser doesn’t support Canvas, sorry.
</canvas>
var canvasElement = document.getElementById("myCanvas");
if (canvasElement.getContext) {
// The Context exists, so we know we have a canvas element
// we can work with.
var context = canvasElement.getContext("2d");
context.fillStyle = "rgb(255,0,0)";
context.fillRect(30, 30, 50, 50);
}
else {
// There is no Context, so we can't do anything.
// Put fall back code here.
}
Results in…
The More Exciting Stuff…
Okay, so I can draw a little red box on a page, woop-de-doo right! This is when I recommend you check out the IETestDrive.com website where the truly cool demos are. Be sure when you’re looking at these demos that you take a minute to look at the source code as well – it’s pretty interesting to see how few lines of HTML are required, and in many cases how few lines of JavaScript as well!
- Amazon Shelf – A visualization of Amazon’s top books and a way to read a bit more into them
- FishIE Tank – Remember the Windows 7 beta fish, he’s back!
- Mr. Potato Gun – Mr. Potato plus what looks like an air canon is never good for Mr. Potato!
- Asteroid Belt – be sure to look at the HTML for this one, there really isn’t any!
- DeemZoom – this is truly making web apps native!
- Canvas Pad – An interactive canvas drawing app
Enjoy!
PEte
Web Site Performance Resources
0At TechEd last week, I presented a session that covered 20 Tips and Tricks for Writing Fast Web Applications. A couple of folks asked for more resources and where they could find more info, and I figured I’d share some of it here more publically.
I’d highly recommend checking out Steve Souders’ two books:
In the coming days/weeks, I’ll get some additional details posted about the 20 tips and tricks that I talked about, and how you can make sure you’re using them on your site!
20 Tips and Tricks For Writing Fast Web Applications
4I’m about 30 minutes from walking on stage to present my last session here at TechEd 2010 in New Orleans and I wanted to share this presentation early, just in case the session room fills up and folks can’t make it in or for those of you who weren’t able to make it. If you’re a TechEd attendee, the slides are up on the Schedule Builder, otherwise, you can find my deck here [8meg PPTX].
The Internet Explorer engineering team spends a lot of time working to understand what developers and doing when building their websites, where the bottle necks are (both in the browser and in the code that developers write). With all of the information that they gathered, they built set of 20 tips and tricks that will help your site run faster, and more efficiently. While the research they did used Internet Explorer as the base, almost all of these tips and tricks apply to all browsers.
Jason Weber presented these tips and tricks at MIX2010 this year – the session web page is at http://live.visitmix.com/MIX10/Sessions/CL29 and you can also download the slides, or the video in MP4, Windows Media Format or High Quality Windows Media Format. It runs about 80 minutes and should be required watching for every developer out there I think. I know I learned a few things and I think my site breaks some of the best practices that I’ve got listed below! (I guess I’ve got some work to do!
)
Without any further ado, I present to you…
20 Tips & Tricks To Improve Your Website Performance
- Ensure server side compression is enabled on “text” like files
- Use conditional requests
- Provide cacheable content
- Minify your JavaScript
- Don’t scale images (I’m really guilty of this one)
- Use image sprites
- Link JavaScript at the bottom of your file, and avoid inline JavaScript
- Add the “defer” tag when you have to link to JavaScript at the top of your page
- Link Style Sheets at the top of your page
- Avoid using @import
- Minimize Walking Look Up Chain
- Cache Function Pointers
- Use the Native JSON object
- Remove duplicate scripts
- Minimize DOM interactions
- Use efficient DOM Methods
- Use querySelectorAll for groups
- Only send required styles
- Simplify your selectors
- Minimize page layouts
PS: If you want a little laugh, go to the TechEd site, and look at my bio – it wasn’t quite supposed to read like that ![]()
[UPDATED 6/10/10 1:25pm PST] Fixed the link to the slides, sorry about that!


