devxlogo

Use Script Caching

Use Script Caching

Using script caching when a script is extremely large or embedded across multiple pages can improve the performance of code in JavaScript. It also allows you to easily distribute one code for use on many pages.

Include the entire script in a .js file as shown below:

 

This causes the browser to load the script only once, and recall it from cache should the page be reloaded or revisited.

By including the above reference, your browser will now download the code stored inside displaydate.js, and run it as if the code was physically typed onto the page. The library file does not have to be stored in the same directory as the page using it. In fact, you can even reference a library that’s on a distant domain! Like this:

 
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist