When to Use Your <head>, When to Link, and When to Make It Inline!

The problem with having choices is knowing which one to choose! Fortunately, by following a few quick and simple rules of thumb, you can come to the right conclusion.

Rule of Thumb 1

If the JavaScript you are using is large, forget inline and go for the <head> or linked file.

Rule of Thumb 2

If you want to add the same JavaScript to many HTML pages, linked files will make adding and updating scripts easy.

Rule of Thumb 3

Want to add a small, one-off JavaScript to a page? Use inline code.

Rule of Thumb 4

Remember that you can mix and match the three types. Use linked files for most of JavaScript you reuse from one page to the next, put other bulky JavaScript in the <head>, and ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.