diTii.com Digital News Hub

Sign up with your email address to be the first to know about latest news and more.

I agree to have my personal information transfered to MailChimp (more information)

Jun072008

Lazy Script Loading: Stop reptitive calls to JavaScirpts

Bob Matsuoka discussed how to lazily load Javascript script files by appending script elements to the HEAD tag in his article “Lazily load functionality via Unobtrusive Scripts.”

A common use of a lazy loader is in conjunction with “require” type function that allows you to specify which scripts are needed for a particular script to execute. Since library scripts are often called by more than one script, I thought it important to allow my lazy loader to track which scripts have already been loaded on a page to prevent unnecessary re-loading.

In this example, I’ve created the LazyLoader.scripts array. As each script is called, this script src is tested against the array of scripts already called, and if it exists, the script is not re-loaded, but its callback is executed. This allows you to call any required script as often as needed with impunity.

Full Article

 

Share This Story, Choose Your Platform!