You must remove duplicate scripts from the website

How including the same javascript twice on the same page affects performance. This is not as unusual as you think

A review of the top 10 US sites reveals that two of them contain duplicate scripts. There are two main factors that increase the chances of a script being duplicated on a web page: computer size and the number of scripts. When this happens, duplicate scripts affect performance by creating unnecessary HTTP requests and wasting javascript execution.

Unnecessary HTTP calls occur in Internet Explorer, but not in Firefox. In Internet Explorer, if an external script is included twice and is not cacheable, it generates two HTTP calls during page loading. Even if the script is cacheable, the extra requests occur when the user reloads the page.

In addition to generating a torrent of HTTP requests, time is wasted evaluating the script multiple times. This redundancy in the execution of Javascript occurs in both Firefox and Internet Explorer, regardless of whether the script is caheable or not.

A solution to avoid accidentally including the same script twice is to implement a script manager module in your template system. The most common way to include a script is by using the SCRIPT tag in your HTML page.

script type = »text / javascript» src = »menu_1.0.17.js» /script

An alternative in php could be to create a function called "insertScript".

? php insertScript ("menu.js")?

In addition, to prevent the same script from being inserted multiple times, this function should handle other issues with scripts, such as adding the version number to the filename to support long-lived Expires headers.

Date update on 2020-11-13. Date published on 2020-11-13. Category: Computer class Author: Oscar olg Fuente: tecnologia