DEV Community

Joan Alba Maldonado
Joan Alba Maldonado

Posted on • Originally published at joanalbamaldonado.com on

4 1

requestAnimationFrame (with high resolution timing, very precise) and performance.now polyfills

Two Vanilla JavaScript polyfills:

I have just adapted the window.requestAnimationFrame polyfill made by Paul Irish to work with high resolution timing automatically (when possible) and improved the performance a little bit. Here it is: https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0

I have also mixed the window.performance.now polyfill made by Paul Irish with Aaron Levine’s and modified some of the code to improve it. Here it is: https://gist.github.com/jalbam/cc805ac3cfe14004ecdf323159ecf40e

Both polyfills can be used either separately or together and they will automatically detect whether the web client needs them or not. Just load them in your code (using your favourite way) and, if the client needs them, the polyfills will deploy and be used.

If you want to use them together, remember to load first the code of the window.performance.now polyfill since the window.requestAnimationFrame polyfill could need it.

Any comments are welcome!

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay