Peas in a pod.
PUT YOUR BEARD IN MY MOUTH
Aqua Utopia|海の底で記憶を紡ぐ

祝日 / Permanent Vacation
i don't do bad sauce passes
Xuebing Du
Jules of Nature
cherry valley forever

Love Begins

Janaina Medeiros
tumblr dot com
Misplaced Lens Cap

JVL
art blog(derogatory)
noise dept.

izzy's playlists!
d e v o n
2025 on Tumblr: Trends That Defined the Year
Game of Thrones Daily

Kiana Khansmith
seen from United States
seen from United States
seen from United States

seen from United States

seen from United States

seen from Argentina

seen from United States

seen from France

seen from United States
seen from United States

seen from United States

seen from United States
seen from United States

seen from United States
seen from United States
seen from United States
seen from Oman

seen from Germany

seen from Malaysia

seen from Germany
@inxtinct
Peas in a pod.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Faster Web with HTML5: Best Practices
Much of HTML5 aims to deliver native browser support for components and techniques that we have achieved through JavaScript libraries thus far. Using these features, when present, can end up delivering a much faster experience for your users. Putting HTML5 and CSS3 to use today can make your web apps more responsive.
TIP 1: USE WEB STORAGE IN PLACE OF COOKIES
While cookies have been used to track unique user data for years, they have serious disadvantages. The largest flaw is that all of your cookie data is added to every HTTP request header. This can end up having a measurable impact on response time, especially during XHRs. So a best practice is to reduce cookie size. In HTML5 we can do better than that: use sessionStorage and localStorage in place of cookies.
These two web storage objects can be used to persist user data on the clientside for the length of the session or indefinitely. Their data is not transferred to the server via every HTTP request, either. They have an API that will make you happy to be rid of cookies.
TIP 2: USE CSS TRANSITIONS INSTEAD OF JAVASCRIPT ANIMATION
CSS Transitions give you an attractive visual transition between two states. Most style properties can be transitioned, like manipulating the text-shadow, position, background or color. You can use transitions into pseudo-selector states like :hover or from HTML5 forms, :invalidand :valid (example with form validation states). But they're much more powerful and can be triggered when you add any class to an element.
TIP 3: USE CLIENT-SIDE DATABASES INSTEAD OF SERVER ROUNDTRIPS
Web SQL Database and IndexedDB introduce databases to the clientside. Instead of the common pattern of posting data to the server viaXMLHttpRequest or form submission, you can leverage these clientside databases. Decreasing HTTP requests is a primary target of all performance engineers, so using these as a datastore can save many trips via XHR or form posts back to the server. localStorage andsessionStorage could be used in some cases, like capturing form submission progress, and have seen to be noticeably faster than the client-side database APIs.
For example, if you have a data grid component or an inbox with hundreds of messages, storing the data locally in a database will save you HTTP roundtrips when the user wishes to search, filter, or sort. A list of friends or a text input autocomplete could be filtered on each keystroke, making for a much more responsive user experience. Certainly view the Web SQL Database tutorial for a comprehensive guide at putting this to work.
TIP 4: JAVASCRIPT IMPROVEMENTS LEND CONSIDERABLE PERFORMANCE ADVANTAGES
Many additional methods were added to the Array protoype in JavaScript 1.6. These are available in most browsers now, except for IE.
TIP 5: USE CACHE MANIFEST FOR LIVE SITES, NOT JUST OFFLINE APPS
Two years back, Wordpress used Google Gears to add a feature called Wordpress Turbo. It essentially cached many of the resources used in the admin panel locally, speeding up file access to them. We can replicate that behavior with HTML5's applicationCache and thecache.manifest.
TIP 6: ENABLE HARDWARE ACCELERATION TO ENHANCE VISUAL EXPERIENCE
In leading browsers, many visual operations can leverage GPU-level acceleration, which can make highly dynamic visual operations much smoother. Hardware acceleration has been announced for Firefox Minefield and IE9 and Safari added hardware-level acceleration in version 5. (It arrived in Mobile Safari much earlier.) Chromium has just added 3D transforms and hardware acceleration for Windows, with the other two platforms coming soon.
GPU acceleration kicks in only under a fairly restricted set of conditions, but 3D transforms and animated opacity are the most common ways to trip the switch.
TIP 7: FOR CPU-HEAVY OPERATIONS, WEB WORKERS DELIVER
Web Workers have two significant benefits: 1) They are fast. 2) While they chug on your tasks, the browser remains responsive. Grab a look at the HTML5 Slide Deck for Workers in action.
Some possible situations where you could use Web Workers:
Text formatting of a long document
Syntax highlighting
Image processing
Image synthesis
Processing large arrays
TIP 8: HTML5 FORM ATTRIBUTES AND INPUT TYPES
HTML5 introduces a new set of input types, upgrading our set of
text, password, and file to include search, tel, url, email,
datetime, date, month, week, time, datetime-local,
number, range and color.
Browser support for these vary, with Opera implementing most at the moment. With feature detection you can determine if the browser has native support (and will offer a UI like a datepicker or color picker) and if not, you can continue to use the JS widgets to accomplish these common tasks.
In addition to the types, a few useful features have been added to our normal input fields. The input placeholder offers default text that clears when you click into them and autofocus focuses the caret on page load so you can interact immediately with that field. Input validation is another thing making its way in with HTML5. Adding the required attribute means the browser won't let the form submit until that field is filled in. Also the pattern attribute lets you specify a custom regular expression for the input to be tested against; with invalid values blocking form submission. This declarative syntax is a big upgrade not only in source readability but also a significant reduction of JavaScript necessary. Again, you can use feature detection to serve a fallback solution if there isn't native support for these present.
Using the native widgets here means you don't need to send the heavy javascript and css required to pull off these widgets, speeding up page load and likely improving widget responsiveness. To try out some of these input enhancements check out the HTML5 Slide deck.
TIP 9: USE CSS3 EFFECTS INSTEAD OF REQUESTING HEAVY IMAGE SPRITES
CSS3 delivers many new styling possibilities that supplant our use of images to represent the visual design accurately. Replacing a 2k image with 100 bytes of CSS is a huge win, not to mention you've removed yet another HTTP request. A few of the properties to familiarize yourself with are:
Linear and radial gradients
Border-radius for rounded corners
Box-shadow for drop shadows and glow
RGBA for alpha opacity
Transforms for rotation
CSS masks
For example you, can create very polished buttons via gradients and replicate many other effects sans-images. Browser support for most of these is very solid, and you can use a library like Modernizr to catch browsers that don't support the features in order to use images in a fallback case.
TIP 10: WEBSOCKETS FOR FASTER DELIVERY WITH LESS BANDWIDTH THAN XHR
WebSockets was designed in response to the growing popularity of Comet. There are indeed advantages to using WebSockets now, instead of the Comet over XHR model.
WebSockets has very light framing, and so the bandwidth it consumes is often lighter than that of XHR. Some reports indicate a 35% reduction in bytes sent across the wire. Additionally, in higher volume the performance difference when it comes to message delivery is more apparent; XHR has been recorded in this test with having an aggregate time of 3500% longer than WebSockets. Lastly, Ericcson Labs considered the performance of WebSockets and found the ping times over HTTP were 3-5 times larger than over WebSockets due to more substantial processing requirements. They concluded that the WebSocket protocol was clearly more suitable for realtime applications.
Author: Paul Irish
An idea that can change the course of the company can come from anywhere.
Jack Dorsey
KEEPING UP WITH HTML5 AND BROWSER SUPPORT
The web moves fast, and sometimes it's hard to keep up. With Chrome autoupdating with every release, and now also Firefox, new features are being directly pushed to end users. This is awesome for developers, as they can create better apps and know their users will have the latest features. Actually keeping up with those features can be a challenge, but only if you don't know where to look. Luckily, there are some key resources that will keep you in-the-know and up to date. Here's a few that I found really useful:
chromestatus.com - tracking HTML5 feature implementations for Chrome
updates.html5rocks.com - short news, tips, and tricks about HTML5
@chromiumdev - short updates and announcements about Chrome and Chrome Developer Relations
Chrome Release Blog - major and minor releases across all channels, summary of changes
Can I Use - a detailed list of HTML5 features and their implementation status across most desktop and mobile browsers. Not necessarily a news source, but a snapshot.
Firefox release notes - release notes for Firefox
The Burning Edge - developments in nightly builds for Firefox
Peter Beverloo's Blog - my personal favorite, thorough coverage of WebKit changes
Follow the above, stay up to date, and build for modern browsers!

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
20 Seconds of Courage: Change is Going to Come
Courage isn’t always found in grand gestures, and it doesn’t have to be about life and death situations. For most of us, any decision with the potential to affect our everyday lives can take a certain amount of courage, sometimes even all the courage we have. For instance; a friend and co-worker recently put in her formal notice of resignation with our employer, and it seems to me that the act of pushing the SEND button on that email would have required significant courage.
Change is almost always scary, regardless of the perceived outcome of the change. Considering that most adults spend the vast majority of their waking lives at work, a change in that space can be fraught with anxiety and fear. Even the most well-thought-out decision means stepping out into the unknown, away from familiar surroundings and (hopefully) friendly faces. So why do we risk these drastic life changes? Is a nicer office, more money, or a step up the career ladder really worth the emotional turmoil?
Fear of the unknown is a powerful force in our lives, as so, to a degree, is fear of failure. The decision to move on to something new can be made even more difficult when one is faced with leaving a position of security, where their work is respected and they are seen as successful. Along with both of these is the fear of how others will perceive us. What will our friends, family and co-workers think of our decision? These are all fears that must be faced, even in the best of scenarios when one is considering changing jobs, and overcoming the inertia created by these fears can be no small feat.
What then did it take to hit the SEND button on that email last week? Courage, fortitude, and faith that she was making a decision that would increase her personal happiness and enrich her life. Is that kind of positive outcome a guarantee? Of course not, and therein lies the need for courage. By being willing to embrace change, by moving past her fears in that 20 seconds of courage, my friend opened a new door for herself, creating potential, and moving past fear.
by LindsayB on 9.1.12 | Business
Better JavaScript Development With ‘JSTerm’ for Firefox
JSTerm, an experimental Firefox add-on for JavaScript developers, has hit version 2.0.
The JSTerm Firefox add-on — not to be confused with the HTML5 Telnet Emulator by the same name — adds a “jsterm” button to Firefox’s Developer Toolbar. Click the button and you’ll get a JavaScript terminal for live coding, prototyping and quick JavaScript experiments. JSTerm behaves like a typical shell terminal with history, tab completion and plenty of key bindings.
Version 2.0 offers performance improvements, a new option to undock the terminal into its own window, global history shared across sessions and support for OS X’s fullscreen mode.
To try out JSTerm you’ll need Firefox 16 (currently in the Beta channel) since JSTerm uses the newGraphical Command Line Interface we covered in our Firefox 16 beta review. JSTerm also takes advantage of the built-in Firefox Source Editor to highlight JavaScript and a sandbox to eval JavaScript.
If you’re thinking there are already several tools for Firefox that cover this ground, well, you’re right. The built-in Scratchpad and WebConsole both offer similar tools, though neither is quite as nice for quick prototyping and experimenting. Developer favorite Firebug also has a Console for JavaScript developers, but it lacks the nice syntax highlighting you’ll find in JSTerm.
For more details on JSTerm and a changelog of everything that’s new in this release, check out Mozilla developer Paul Rouget’s blog. To have a look at the code behind JSTerm, head to GitHub.
Author: Scott Gilbertson
Can HTML5 Help Find a Cure for AIDS?
There is a volunteer computing project going on right now called “Social Docking” that is written entirely using HTML5 and is run completely within the web browser. It’s an initiative to find compounds of pharmaceutical interest towards AIDS and Alzheimers. All you have to do is visit this HTML5 app socialdocking.appspot.com and let the app be in your browser for about 10 minutes before closing it. You can open a new window to browse the web or do whatever you want on your computer during that time. The idea is to get the simulation to run for 3000 iterations. This low cost supercomputing project will help researchers study three molecules including, HIV-1 integrase, which is a promising target for an AIDS vaccine.
The advantage of socialdocking.appspot.com is that it is web-browser based (as opposed to client-based Folding@Home, SETI@Home, which use BOINC). It also integrates as a Facebook app at http://apps.facebook.com/socialdocking but ChemDoodle’s XHR level 2 doesn’t work when Facebook users have SSL enabled on their accounts. Eric Jang, the app’s creator, had to remove the WebGL-related things from ChemDoodle and modify it to use JQuery Pollen AJAX methods. Thanks to level 2 XHR to fetch chemical structures from SMILES strings + Web Workers, the virtual screening app automatically retrieves the next available job once it finishes docking one chemical. It can be run for $0 using Google App Engine’s free billing scheme. Right now, web browsers have not put a lot of effort towards implementing the subworkers specification of Web Workers because there are not many applications found for Web Workers. The hope is that cheap supercomputing projects like these will improve the attention Web Workers receives from web browsers.
Here is more on the science behind this great HTML5 app from the app’s creator Eric Jang.
Developing new drugs is super expensive. It takes a billion dollars and years of clinical trials for company like Pfizer to roll out a new drug into the market. One way that these companies save a lot of time and money is to use Virtual Screening – instead of testing every possible drug candidate in a test tube, they refine a massive database of chemicals by simulating the molecular physics that go on when a drug binds to a receptor. This is called the lock and key model, which states that if a ligand binds strongly to a receptor, it is likely to induce some kind of change with the receptor, and hopefully to some beneficial effect within the cell.
For this project, I am studying three molecules at the same time and trying to find ligands that bind strongly to them. The blue one on the left is HIV-1 integrase, which is a promising target for an AIDS vaccine because it is critical for the HIV virus integrate itself into the host’s DNA replication system. The second one is Acetylcholinesterase, which can be targeted for treating Alzheimers and other forms of dementia. Acetylcholinesterase breaks down a neurotransmitter, so I’m interested in targeting the inhibitor domain that hopefully will render Acetylcholinesterase inactive. Finally, the telomeric RNA quadruplex is a unique secondary structure that personally I have been interested in for some time because I’ve done research on the past with telomeres and G-quadruplexes. It would be really interesting to find some kind of chemical side chain that binds to the arm loops and can allow us to study its role in telomerase regulation and find out more about the topology of quadruplexes.
Please visit the Social Docking app. It might be the first practical distributed computing application that uses HTML5 Web Workers.
Author: Stan Byme
New Drag and Drop HTML5 App Building Tool
Making an HTML5 app just got easier. Sencha, a provider of HTML5 frameworks and tools for desktop and mobile application developers, just released Sencha Architect 2. Sencha Architect 2, is a HTML5 visual app builder that was created using Sencha’s own HTML5 tools. It includes full code editing capabilities and built-in one-click native packaging for iOS and Android that eases app deployment to Apple’s app store and Google Play.
High Performance HTML5 is by far the favorite session from Google I/O 2012. The session was done by Steve Souders who is like the Michael Jordan of speed on the web. His web credits include creating YSlow, HTTP Archive, Cuzillion, Jdrop, ControlJS, and Browserscope. He is the Head Performance Engineer at Google and wrote High Performance Web Sites and Even Faster Web Sites. He also co-chairs Velocity. Do you get the idea? This guy is all about speed.
The speed of an HTML5 app is crucial to it’s success. A good user experience is a fast user experience.
Source: HTML5 Blog

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Re-Introducing Canvas
When HTML5 was put together, a lot was about improving features that existed in the past, adding more semantics and making quite a few things "web native" that historically were only possible with Flash or other plugins. Many of those features were welcome throughout the web community — after all, who could say no to native audio and video with improved accessibility? Others, however, caused a few raised eyebrows.
Canvas the troublemaker
One thing that appeared as an amazing opportunity, but also didn't sit too well with markup purists, was the canvas element. There were quite a few interesting concerns about it, many of them still unresolved.
• Without JavaScript, a canvas element does nothing in a browser. Canvas is one of the elements that fortify the dependency on JavaScript in modern web development. Purists of HTML had problems with that, because JavaScript is strongly tied to the browser. It is not a part of the abstract web stack of HTML being sent over HTTP, and can only be consumed by a browser specifically able to execute the JavaScript.
• There is no accessibility in the canvas element. When you modify it via script, nothing in the HTML DOM changes, meaning assistive technology like screenreaders will not get notified of any change. This confused people. It felt like re-inventing Java Applets or having a black box in the page — something we accused Flash of being, while claiming HTML5 was the cure for that dilemma.
• There was no fallback for it. We just did not have anything like that in HTML before, so we were confused as to how to progressively enhance this without blocking out older browsers. After all, HTML5 claimed to be backwards compatible, but there was nothing in HTML4 to which canvas was comparable.
• Old versions of Internet Explorer do not support canvas, which made it a no-go for a lot of developers.
First things first: providing a fallback
Yes, not every browser out there supports canvas. But that doesn’t mean you should just tell the people who come to your site to download another browser you are very excited about. This doesn’t help the web as a whole, and in many cases the people coming to your site cannot do that.
On the other hand, shoe-horning new technology into old browsers with libraries and shims may make us feel good because we are not leaving people out, but it also makes us a slave to old technology. If you use a library to bring canvas functionality to Internet Explorer 6, you also make an agreement to test in that browser and make sure that what you did performs well in it. Do you want to spend that time?
The best way to deal with this situation is to provide a fallback that makes sense and gives people something to look at or look forward to. Instead of telling people to change, you just show them what they are missing. With luck, this will entice them to upgrade or change.
The simplest way of doing that is to show an image as the fallback:
<canvas> <img src="screenshot.png" alt="screenshot of the rotating elephant animation"> </canvas>
This does a few things: it tells the visitor that they are missing something, it provides a fallback for assistive technology, and, as an extra bonus, you provide an image that link services could offer as a thumbnail. Say, for example, you want to promote your cool canvas-based effect on Facebook. It would offer this screenshot as the preview — handy, isn’t it?
For animations, you could provide a video as the fallback, and a static image as a secondary fallback for the video to make everybody happy. Got it? Cool, let’s move on.
What is canvas good for?
So what exactly does canvas allow us to do that we couldn’t before? Well, it is — as the name says — a canvas in the page. You can use it to paint things, with a very low-level API and a few lines of code. To see this in action, check out this example on jsFiddle.
Simple ways of drawing
As you can see, it is very simple to allow a user to paint something inside your document. The Canvas painting APIis ridiculously simple (which was another criticism leveled by developers accustomed to more sophisticated APIs like the ones Flash provides us with) but there is a reason for it: canvas was made for speed. The thinking was that the simpler it is, the more performant it would be. Canvas was meant to allow us to create dynamic graphics, but also to show things quickly on the page — meaning gaming in the browser is not science fiction or the task of plugins any longer.
When you scratch the surface of canvas, however, you will find that there is much more to the little element and the API than meets the eye. Imagine the canvas as a piece of paper and you have a pen in your hand. You can move the pen to a certain place on the canvas with the moveTo() method. This places the pen there, but it doesn’t leave a mark yet.
If you want to paint something you have the lineTo(), arc(), arcTo(), quadraticCurveTo(),bezierCurveTo() and rect() functions. You can also just paint rectangles using fillRect() andstrokeRect(). You start new parts of your painting with beginPath() and you end them with closePath()(which is a bit annoying, and the opposite of begin is end and not close). All of these are explained in this drawing shapes with canvas tutorial.
You can also change your pen to paint in different colours and widths (explained in this applying styles and colours to canvas tutorial). You can choose a stroke style, a stroke width, a stroke and fill colour, the line ending (round, butt or rectangle), and you can define how lines should join. And if that’s not enough, you can also define gradients and drop shadows for your paintings. You can even define the compositing you want to have, which means that new paintings do not simply paint over the others but make them darker or lighter or replace part of them. Text is also supported, and you can write from a certain coordinate in all directions and rotations.
You can wipe your canvas using a clearRect() over its whole size or by resizing it dynamically.
A colourful etch-a-sketch in your page?
In the past, I always referred to canvas as an Etch-a-Sketch in your page (which actually inspired my colleague Gregory Koberger to develop a fully working canvas Etch-A-Sketch) — you can paint on it and wipe it and that is it — nothing there remains behind in the DOM or anywhere as an object. That is oversimplifying it, though, as you can retain what you painted and there are a few more tricks up canvas’ sleeve.
A dynamic coordinate system
One of the things that might be hard to get your head around at first is that the coordinate system of the canvas is not fixed. By default, the coordinate system starts at the top left at (0,0) and goes to width and height of your canvas on the bottom right. But you can change that system any way you want to whilst you paint. As explained in this canvas transformations tutorialyou can save and restore the coordinate system of the canvas and scale, rotate, and translate it any way you want.
Jolly good, you might say, but what does that mean? Well, it means that you can draw a shape once and do all the necessary calculations to do that, and if you want to copy it in different sizes and rotations on different parts of the canvas, all you need to do is to change the underlying coordinate system instead of recalculating all the points. This makes canvas not an Etch-a-Sketch in the page, but a cutout animation tool with transparency layers over a background. You can even stretch and rotate all these transparencies without ripping them or losing quality. And that was good enough for Monty Python's Terry Gilliam to produce something awesome, so it should be good enough for you.
Storing, converting and sharing
This still leaves the issue of your paintings not being stored. Of course canvas has a solution for that — one that is bafflingly useful when it comes to images in the browser. With canvas you have pixel-level access to everything that is in it. You can use getImageData() to read all the pixels as an array containing the red, green, blue and opacity values of each pixel. You can manipulate this array and write it back using putImageData(). You can also use toDataURL() to create a data URL from the array that you can save as a PNG or set as the src value of an image in the page.
Working with images
There are many more ways to manipulate images with canvas, mostly using thedrawImage() method to, well, draw images onto the canvas. You can also scale and rotate the images, and even crop parts out of one image to re-use in your new collage. The fun thing about this is that not only can you use images as a source, but you can also grab frames from a video element in the page and do things with that one.
The limit is your imagination — and sometimes the performance
Using all of this, you can do incredible things with the black sheep of the HTML5 element arsenal. Check out thesecanvas demos complete with source codes to get some inspiration. Of course, with lots of power comes some responsibility, and it is important to follow a few canvas performance best practices when you start animating your ideas. But that should not hold you back — you can always optimise once you are happy with what you created.
Thinking outside the box
It is very tempting to use canvas for what it is meant to do — paint stuff in the browser. But now that you know about its dynamic coordinate system and the option to access each pixel, have a go at thinking what can be done with that. It is exciting to see what people come up with. Michal Budzynski for example used array manipulation to create 3D images from normal images in canvas, I used image manipulation to create an in-browser thumbnail generator and a bookmarklet to crop images in any web site or a way to add a blue beanie to your photo to celebrate web standards day.
Resources
• Mozilla has a very detailed HTML5 canvas overview page with links to other tutorials, libraries and demos
• Jacob Seidelin has a great Canvas cheat sheet that has everything you need on two pages
Author: Christian Heilmann
HIGH DPI CANVAS
INTRODUCTION
HiDPI screens are lovely, they make everything look smoother and cleaner. But they also present a new set of challenges to developers. In this article we are going to take a look into the unique challenges of drawing images in the canvas in the context of HiDPI screens.
THE DEVICEPIXELRATIO PROPERTY
Let's start at the beginning. Back before we had HiDPI screens a pixel was a pixel (if we ignore zooming and scaling for a bit) and that was it, you didn't really need to change anything around. If you set something to be 100px wide that was all there was to it. Then the first few HiDPI mobile handsets started popping up with the slightly enigmatic devicePixelRatio property on the window object and available for use in media queries. What this property allowed us to do was understand the ratio of how pixel values (which we call the logical pixel value) in - say - CSS would translate to the actual number of pixels the device would use when it came to rendering. In the case of an iPhone 4S, which has a devicePixelRatio of 2, you will see that a 100px logical value equates to a 200px device value.
That's interesting, but what does that mean for us developers? Well in the early days we all started to notice that our images were being upscaled by these devices. We were creating images at the logical pixel width of our elements and, when they were drawn out, they would be upscaled by the devicePixelRatio and they'd be blurry.
Figure 1 - An image being upscaled and blurred due to the devicePixelRatio
The de facto solution to this has been to create images scaled up by the devicePixelRatio and then use CSS to scale it down by the same amount. So when the device scales it back up using the devicePixelRatio it won't have been scaled beyond its original size and it will no longer be blurry. Problem solved. (Of course that in general terms probably means you're sending images that are overly large for normal DPI devices, but that's a different issue!)
INTRODUCING THE BACKING STORE
What about the canvas? Well that's what we will cover in this article, and to warn you upfront we will be primarily marking out an implementation difference between Chrome and Safari 6 on desktop. There is a newly-exposed, prefixed (and verbosely named) property on each canvas context: webkitBackingStorePixelRatio. Right now Mozilla, Opera and Microsoft do not have an analogous property available in their canvas contexts, but it may well appear in the future.
With that said, the webkitBackingStorePixelRatio property tells us in the given browser what the backing store size is in relation to the canvas element itself. In case you're wondering what the backing store is, whenever you draw anything into the canvas's context, you're really having the browser write it to the underlying storage for the canvas (called its backing store). When the browser comes to draw the canvas to the screen it uses the backing store's data. That means that webkitBackingStorePixelRatio tells us the dimensions of the backing store in relation to the canvas's dimensions. In case you're wondering why you can't use the devicePixelRatio to determine the backing store size, the answer is that they aren't guaranteed to match. Despite presenting the same devicePixelRatio value, Chrome and Safari 6 can and do have entirely different approaches for the backing store size (and therefore the webkitBackingStorePixelRatio) on HiDPI devices. The net result is that we can't rely on devicePixelRatio to know how the browser is going to scale images that are written into the canvas.
OK, so we know what the webkitBackingStorePixelRatio is, but we need to know what its implications are. For the sake of simplicity let's say we have a canvas that is 200px wide and a webkitBackingStorePixelRatio value of 2. Our underlying backing store, therefore, will be 400px wide. It's worth noting that there's nothing to say for sure that the ratio will be 2, it could just as easily be some other value, depending on the browser and device.
Figure 2 - The canvas element and how it relates to its backing store
When the browser gets to drawing out the canvas it is scaled down according to its logical pixel value of 200px, the value that we chose earlier. But then the devicePixelRatio takes over and it will be scaled back up again. If we assume that our devicePixelRatio is also 2, the same as our webkitBackingStoreRatio, it will be 400px wide. Again, its might not be 2; the Nexus 7, for instance, has a devicePixelRatio of around 1.325. You'd be forgiven for being very confused at this point, but you can think of it like this:
Figure 3 - The canvas element being scaled and rescaled
Now we're getting closer. We know what the webkitBackingStorePixelRatio and devicePixelRatio values are used for, but we now need to talk about the implementation differences.
IMPLEMENTATION DIFFERENCES
On a HiDPI device such as a Macbook Pro with Retina display, Safari 6 carries a webkitBackingStorePixelRatio value of 2 and a devicePixelRatio of 2 whereas Chrome uses a webkitBackingStorePixelRatio value of 1 and a devicePixelRatio of 2. This means that if you draw an image into a canvas in Safari it will automatically double the dimensions of the image when writing it to the canvas's backing store, so after scaling down to the logical pixel size and back up again through the devicePixelRatio you will arrive back at the size you specified. In Chrome, however, the image will be written to the backing store at the exact size you specify which means that after the devicePixelRatio is applied it will be upscaled and blurry. A picture speaks a thousand words, so below is an HTML5 Rocks image that has been drawn into a canvas:
Figure 4 - Side by side comparison of HiDPI rendering in Chrome and Safari 6
You'll notice that by default Chrome's rendering is blurry compared to Safari 6's because our image is being written into the canvas backing store at the width we specify then upscaled by the devicePixelRatio.
That leaves two questions: why does Chrome not automatically upscale backing stores in the same way as Safari 6 and how can you as a developer ensure that you can draw images at the scale you choose?
Let's deal with the automatic upscaling question first. As I mentioned earlier there is no guarantee that the backing store ratio will be 2, it could be completely different, possibly more than 2. But if you consider a value of 2 then your backing store will be double the canvas size in both width and height, and that means four times the amount of memory is required to service your canvas element. If you have multiple canvas elements or your code is running in a memory-constrained environment such as on mobile then you're more likely to exhaust your resources. By not doing the upscaling automatically you have the option to do it or not, it's totally your call.
That leaves us with what you can do to manually upscale your canvas. The answer is pretty simple: upsize your canvas width and height by devicePixelRatio / webkitBackingStorePixelRatio and then use CSS to scale it back down to the logical pixel size you want. Taking our above case where Chrome reports a webkitBackingStorePixelRatio of 1 and a devicePixelRatio of 2 we would scale the dimensions of the canvas by 2 / 1, i.e. multiply them by 2, then we would use CSS to scale it back down.
Finally the last thing we need to account for is that since we have scaled up our canvas manually (and reduced it back down using CSS) we now have to make sure we scale up the width, height and positions of our images proportionally.
The code for that looks like this:
/** * Writes an image into a canvas taking into * account the backing store pixel ratio and * the device pixel ratio. * * @author Paul Lewis * @param {Object} opts The params for drawing an image to the canvas */ function drawImage(opts) { if(!opts.canvas) { throw("A canvas is required"); } if(!opts.image) { throw("Image is required"); } // get the canvas and context var canvas = opts.canvas, context = canvas.getContext('2d'), image = opts.image, // now default all the dimension info srcx = opts.srcx || 0, srcy = opts.srcy || 0, srcw = opts.srcw || image.naturalWidth, srch = opts.srch || image.naturalHeight, desx = opts.desx || srcx, desy = opts.desy || srcy, desw = opts.desw || srcw, desh = opts.desh || srch, auto = opts.auto, // finally query the various pixel ratios devicePixelRatio = window.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1, ratio = devicePixelRatio / backingStoreRatio; // ensure we have a value set for auto. // If auto is set to false then we // will simply not upscale the canvas // and the default behaviour will be maintained if (typeof auto === 'undefined') { auto = true; } // upscale the canvas if the two ratios don't match if (auto && devicePixelRatio !== backingStoreRatio) { var oldWidth = canvas.width; var oldHeight = canvas.height; canvas.width = oldWidth * ratio; canvas.height = oldHeight * ratio; canvas.style.width = oldWidth + 'px'; canvas.style.height = oldHeight + 'px'; // now scale the context to counter // the fact that we've manually scaled // our canvas element context.scale(ratio, ratio); } context.drawImage(pic, srcx, srcy, srcw, srch, desx, desy, desw, desh); }
If you want to see what that looks like (and you have access to a HiDPI screen) take a look at the demo page which shows the code automatically scaling the canvas in Chrome (as well as ensuring the image is drawn at the correct size and position) while leaving Safari 6 unaffected. It's important that we only apply this in the situation where the backing store is not automatically scaling up content because if we manually upscale it and then the browser does the same we would find ourselves in the position where the content is upscaled twice which could push memory consumption through the roof.
Going forward we are going to see an increasing number of devices and screen ratios. Understanding how the browser manipulates the images and canvases in your applications through the backing store's pixel ratio and the device pixel ratio is key to ensuring the best possible performance and quality.
Source: HTML5 Rocks By Paul Lewis
WHEN MILLISECONDS ARE NOT ENOUGH: PERFORMANCE.NOW()
The High Resolution Timer was added by the WebPerf Working Group to allow measurement in the Web Platform that's more precise than what we've had with +new Date and the newer Date.now().
So just to compare, here are the sorts of values you'd get back:
Date.now() // 1337376068250 performance.now() // 20303.427000007
You'll notice the two above values are many orders of magnitude different. performance.now() is a measurement of floating point milliseconds since that particular page started to load (the performance.timing.navigationStart timeStamp to be specific). You could argue that it could have been the number of milliseconds since the unix epoch, but rarely does a web app need to know the distance between now and 1970. This number stays relative to the page because you'll be comparing two or more measurements against eachother.
MONOTONIC TIME
Another added benefit here is that you can rely on the time being monotonic. Let's let WebKit engineer Tony Gentilcore explain this one:
Perhaps less often considered is that Date, based on system time, isn't ideal for real user monitoring either. Most systems run a daemon which regularly synchronizes the time. It is common for the clock to be tweaked a few milliseconds every 15-20 minutes. At that rate about 1% of 10 second intervals measured would be inaccurate.
USE CASES
There are a few situations where you'd use this high resolution timer instead of grabbing a basic timestamp:
benchmarking
game or animation runloop code
calculating framerate with precision
cueing actions or audio to occur at specific points in an animation or other time-based sequence
AVAILABILITY
The high resolution timer is currently available in Chrome (Stable) as window.performance.webkitNow(), and this value is generally equal to the new argument value passed into the requestAnimationFrame callback. Pretty soon, WebKit will drop its prefix and this will be available through performance.now(). The WebPerfWG in particular, led by Jatinder Mann of Microsoft, has been very successful in unprefixing their features quite quickly.
In summary, performance.now() is...
a double with microseconds in the fractional
relative to thenavigationStartof the page rather than to the UNIX epoch
not skewed when the system time changes
available in Chrome stable, Firefox 15+, and IE10.
_____________________________________________________________________
Source: HTML5 Rocks by Author: Paul Irish
Save a man from drowning, you are responsible to him for life.
A very famous Chinese saying
One of the loveliest place on Earth. Thira. Greece.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Joining together to take on the world with our heavy metal / Spreading the message to everyone here, Come let yourself go .. Metal Miltia (Kill 'em All, 1983, METALLICA)
The true university of these days is a collection of books.
Thomas Carlyle (via kaajoo)