javascript - jQuery: Lazy Loading for JS -


i read http://ajaxpatterns.org/on-demand_javascript , got interested in "lazy loading" js. questions:

  1. can recommend plugin this?
  2. any "real world" advice implementing such strategy? "gotchas" should out for?

no plugin needed. can use jquery's $.getscript(). put particular event's javascript in separate file, bind event calls $.getscript().

$(function() {     $('#yourelement').click(function() {         $.getscript('/path/to/script.js');     }); }); 

this ensure never load more javascript need to. if user never clicks on element, never loaded javascript event. there small delay http request, should indicate loading animation on click while script loads.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -