Why inline JavaScript is bad?

It’s not recommended to inline static resources (in your case, the inline javascript) since you can’t cache them.

Caching a static resource reduces the size of page loads – thus increasing the page load speed – for returning visitors. However it comes at the cost of an additional HTTP request which should be avoided.

Whenever the static resource is so small that the additional size is negligible in comparison to a HTTP request, then it’s actually recommended to keep that resource inline.

It’s usually a good idea to keep javascript libraries in external (cacheable) documents, while keeping small amounts of scripts inline.

So, in response to your headline – inline javascript isn’t bad per-se. It’s a balance whether or not it’s worth a HTTP request to cache the resource.

Leave a Comment