devxlogo

Efficiently Sharing Common Client Script Code Across Pages

Efficiently Sharing Common Client Script Code Across Pages

When you have multiple web pages calling the same client script code, locate the shared script code in a separate file (e.g. Shared1.js) and reference the shared code in each page through the use of the SRC property of the

The script file will be downloaded by the first page that references it. Subsequent references will pull the file from the browser cache rather than requiring another download. This is more efficient than other options, such as coding the script in each page or using an ASP include file, which adds the script code to each downloaded page, increasing the page size.

In addition, rather than creating one large common script file, modularize your script files so that script code is not downloaded until it is likely to be referenced by an HTML page.

devx-admin

Share the Post: