Featured post
performance - Javascript and website loading time optimization -
i know best practice including javascript having code in separate .js file , allowing browsers cache file.
but when begin use many jquery plugins have own .js, , our functions depend on them, wouldn't better load dynamically js function , required .js current page?
wouldn't faster, in page, if need 1 function load dynamically embedding in html script tag instead of loading whole js js plugins?
in other words, aren't there cases in there better practices keeping our whole javascript code in separate .js?
it seem @ first glance idea, in fact make matters worse. example, if 1 page needs plugins 1, 2 , 3, file build server side plugins in it. now, browser goes page needs plugins 2 , 4. cause file built, new file different first one, contain code plugin 2 same code ends getting downloaded twice, bypassing version browser has.
you best off leaving caching browser, rather trying second-guess it. however, there options improve things.
top of list using cdn. if plugins using popular ones, chances being hosted cdn. if link cdn-hosted plugins, visitors hitting site first time , have happened have hit site that's using same plugins same cdn, plugins cached.
there are, of course, other things can to speed javascript up. best practice includes placing script include tags close bottom of document possible, not hold page rendering. should lazy initialization. involves, stuff needs significant setup work, attaching minimalist event handler when triggered removes , sets real event handler.
- Get link
- X
- Other Apps
Comments
Post a Comment