Avoid include JavaScript Files | CAST Appmarq

Avoid include JavaScript Files


Rule Definition
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.

Remediation
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. For other limit the size.

Violation Code Sample
<%@include file="script.js" %> // VIOLATION
or 
<jsp:include file="script.js"> // VIOLATION
Fixed Code Sample
<SCRIPT TYPE="text/javascript" SRC="script.js'> // FIXED

or

<SCRIPT LANGUAGE="JavaScript" SRC="script.js'> // FIXED

Related Technologies
JEE

Health Factor

  Total Quality Index


Technical Criterion
Efficiency - Memory, Network and Disk Space Management

About CAST Appmarq

CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.

Benchmark Statistics

Global Compliance

90.60%

Total Violations
1,973
Total Opportunities
21,000
Average Violations / App.
6.15
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Financial Services

82.57%

Utilities

44.32%

Manufacturing

80.49%