Page Speed: Combine external JavaScript

Combining external scripts into as few files as possible cuts down on RTTs and delays in downloading other resources.

recommends:

Partition files optimally

Here are some rules of thumb for combining your JavaScript files in production:

  • Partition the JavaScript into 2 files: one JS containing the minimal code needed to render the page at startup; and one JS file containing the code that isn't needed until the page load has completed
  • Serve as few JavaScript files from the document <head> as possible, and keep the size of those files to a minimum.
  • Serve JavaScript of a rarely visited component in its own file. Serve the file only when that component is requested by a user.
  • For small bits of JavaScript code that shouldn't be cached, consider inlining that JavaScript in the HTML page itself.

Position scripts correctly in the document head.

Whether a script is external or inline, it's beneficial to position it in the correct order with respect to other elements, to maximize parallel downloads.

Read More

Have an idea for this recommendation?

Feel free to contact us with your suggestions, links or ideas!