background preloader

RequestAnimationFrame for smart animating

RequestAnimationFrame for smart animating
If you’ve never written code to animate inside the browser, you can stop reading :) What is requestAnimationFrame? In your animation work, you’ve used a timer loop to make changes every few milliseconds. Good for us: browser vendors have decided, “hey, why don’t we just give you an API for that, because we can probably optimize some things for you.” Why should I use it? The browser can optimize concurrent animations together into a single reflow and repaint cycle, leading to higher fidelity animation. OMG I can brag about having a site with battery-friendly animations? Yeah bro. How should I use this? Note: I am using ‘requestAnimFrame` here because since the spec is still in flux, I don’t want to make a straight polyfill, yet. 2012.01.07: The spec has gotten some fixes and settled down. A robust polyfill Opera engineer Erik Möller wrote about rAF and developed a polyfill that better handles browsers without native support. I have this polyfill available as a gist as well. Is it ready? Related:  Generative Art

sole/tween.js 10 Best Node.js MVC Frameworks for JavaScript Developers Node.js is one of the most popular javascript framework that allow to build scalable network web applications. Node.js contains a different kind of frameworks such as MVC framework, full-stack framework, REST API and generators, lots of libraries as server library that making it possible to sun a web server without use of external software such as Apache and Lighttpd. These frameworks makes it more user-friendly and easy to use, also supports a large number of features and functionality to develop huge web applications in just follow few steps. Last weak we had come with some best javascript frameworks for web developers. 1) A Node.js Framework – Sails js Sails is one of the excellent framework that make it easy to develop custom, enterprise-grade and modern Node.js apps, also it’s good for building charts, dashboards and multiple games. 2) A Node.js Framework - Total js 3) A Node.js Framework - Partial js 4) A Node.js Framework - Koa js 5) A Node.js Framework - Locomotive js - Find websites hosted on the same IP-address Improving HTML5 Canvas Performance Introduction HTML5 canvas, which started as an experiment from Apple, is the most widely supported standard for 2D immediate mode graphics on the web. Many developers now rely on it for a wide variety of multimedia projects, visualizations, and games. However, as the applications we build increase in complexity, developers inadvertently hit the performance wall. There’s a lot of disconnected wisdom about optimizing canvas performance. Note that this article does not go into usage of HTML5 canvas. Performance testing To address the quickly changing world of HTML5 canvas, JSPerf ( tests verify that every proposed optimization still works. Visitors to a JSPerf performance test page can run the test on their browser, and let JSPerf store the normalized test results on Browserscope ( All of the performance results in this article are keyed on the browser version. Pre-render to an off-screen canvas no pre-rendering: pre-rendering: can2.width = 100; can2.height = 40;

Animation Usually, a framework handles the animation for you. However, you may wonder how the animation is implemented in pure JavaScript, and what are the possible problems. Understanding the technique is also essential to create complex animations. Even with the help of frameworks. The basics of the animation The JavaScript animation is implemented as gradual changing of DOM element styles or canvas objects. The whole process is split into pieces, and each piece is called by timer. The pseudocode is: The delay between frames is 10 ms here, which means 100 frames per second. In most JavaScript frameworks it is 10-15 ms by default. If the animation requires many calculations, CPU may get 100% load, and things become sluggish. We’re using setInterval, not recursive setTimeout, because we want a frame once per interval, not *a fixed delay between frames. Example For example, the element is visually moved by changing from 0 to 100px. Open the code in new window Click to animate: delay start

jQuery: The Write Less, Do More, JavaScript Library Build an Offline HTML5 Web Application Browser Support Before delving into any latest technology, you should always perform a quick spike on browser vendor and platform support. Otherwise, you risk writing something that will only benefit a select few users. With respect to Offline Apps, the news is good! According to, all class A browsers and mobile devices support offline applications, with the exception of Internet Explorer 9 (version 10 will support them) and Opera Mini versions 5.0 to 7.0. Firefox and Chrome offer the most support, with Firefox going back 21 versions and Chrome 23! Good Candidates for the Offline Treatment Sites that make good offline apps offline generally fall into two categories: those that let you manipulate data and those that let you search and retrieve information. The Undependable online and offline Events You may have heard of the navigator.onLine property. The check for the 'online' property is important because most browsers don't support the online and offline Events. Conclusion

method_exists() vs. is_callable() One thing I often see when re-factoring PHP applications, is the improper use of the method_exists() function, and I think this needs a little bit of clarification. Here is a typical example of what I’m talking about: The purpose of this code snippet is quite easy to understand (even if I don’t encourage to do this kind of not-very-OOP-stuff): having an object named “$object”, we try to know if it has a method named “SomeMethod”, if so, we call it, and provide some arguments to it. This code will probably run very well during all its lifetime, but what if the object’s method is not visible from the current scope (like… a private or protected method)? The real intent of the previous code snippet was in fact to know if the application could call a method on the object, from the current scope. This is why (among other reasons) is_callable() is part of the PHP built-in functions. Here is another snippet of code to illustrate the differences between method_exists() and is_callable() in action: