Book a consultation

30 minute meeting

Thank you

We’ll reach out within one business day. If you don’t hear from us, check spam and promotions folders.

Contact us

Fill out the form to send us a message

Attach related materials (.pdf, .docx, .odt, .rtf, .txt, .pptx; max 5 MB)
Or

17.10.2011

1 min read

Javascript optimization

Downloading resources in parallel mode Modern browsers can download resources in several threads. But in some cases threads can be blocked. External script in section may block downloading subsequent resources. This is why it is better to include all cascade style sheets in the beginning of section, and all external scripts at the end (Properly including stylesheets and scripts). The other way is to use “defer” and “async” html attributes, which force browser to download scripts in asynchronous mode. Dynamic script linking There are several ways to link external scripts dynamically:

  • document.write(‘’);
  • document.createElement(“script”);
  • XMLHttpRequest

The worst is document.write(), as it blocks DOMLoaded event from triggering. Using document.createElement() is better, as it doesn’t block DOMLoaded event. But it shows page loading indicator at the top of page. The best solution is to use XMLHttpRequest. It provides total control on script loading process. Javascript optimization. Reflow/relayout To speed up DOM manipulation routines modern browsers use separate rendering tree. When script modifies some DOM properties no reflow/relayout occurs. Affected elements in render tree are just marked as “dirty”. Relay out occurs only when page is (re)drawn or when script tries to read property of “dirty” element. One should remember that undue reading of DOM properties may lead to continue reflow. So it is much faster to read and calculate all required values first and only then update, than to update during reading. (Minimizing browser reflow).   Sergey G., Senior developer, Head of PHP department Binary Studio

Thank you

We’ll reach out within one business day. If you don’t hear from us, check spam and promotions folders.

Looking for a tech partner to help you scale your project?

Let’s schedule a quick call to explore how we can support your business objectives.

Christina Berko

Let’s schedule a quick call to explore how we can support your business objectives.

Christina Berko

Client Manager

0 Comments
name *
email *

Featured Case Studies