Javascript in HTML can be unreadable and cause reliability issues

Software ResiliencyCode Reliability

Why you should care

Including JavaScript files in HTML is not ideal as some browsers cannot read an external Javascript file and usually renders it completely blank. It usually requires importing a Jquery. Having Javascript files be unreadable in HTML can cause reliability issues.

Business Impacts

It is recommended to avoid JavaScript in HTML as it cannot be accessed by browsers making the code unreadable, inaccessible and unproductive. It can also be a waste of resources if the code is designed to be accessed as a website.

Production Risk

CAST Recommendations


Style Guide

How we detect

This code insight shows that JavaScript includes are sent by the server each time the page that include it is loaded. If you use the HTML tag to refer to this file, the browser doesn’t have to query for the static content for every page request. Most popular browser like IE, FireFox, Safari, Opera first check their local cache for the static file/resource and only if they don’t find do they make a request to the web server for the same.
For JSP: create a link (html tag) instead of an include. It will be stored in the client cache instead of being sent each time the page is loaded

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.

See featuresHow it works