asp.net - Using ScriptManager CompositeScript to bundle scripts -


i'm using asp .net 3.5 , looking way bundle bunch of scripts. came across scriptmanager's compositescript element. way solution use bundling? have ramifications etc?

pros , cons, traps similar other script bundling solutions-- want minimize first, pay attention order of scripts, start scripts ; close off unclosed scripts in file.

one asp.net specific issue debug/development experience. if combine scripts, more difficult find code in ie debugger, script have machine generated name looks similar other framework generated scripts & code buried in larger file.

so register references in code behind , wrap them in ifdef debug/endif , ifdef release/endif (be sure define release in project properties, doesn't happen default if use trick). in release version, bundle scripts , debug version leave files separate.

also per microsoft's recommendation, script bundling works best files need throughout website. if have multipage site a, b, c , users visit 1 of them, bundling files a,b,c give user 2 files. think bad micro-optimization because apps have small javascript files & large libraries, website's worth of js bundled not enough bytes worry about, unless have lot of traffic.

finally, server side scriptmanager doesn't offer way defer scripts or dynamically trigger load client side (other load scripts after ui), use lab.js dynamically load scripts later... can allow defer script until know need , possibly defer loading script forever. once bundle script, loaded each user if turn out need or not..

part 2 gotcha, @ least me, while can enable caching of js files in web.config (no time syntax @ moment!) , can enable caching @ iis level using expires header, scriptmanager nothing "bust" cache when new version comes out. ideally, script management tool let trick browser thinking script in folder changes last update changes, scripts client side cached year.

i wish had info on if scripts server side cached-- guess not. because user gets script once per day @ -- on server seem cache 24 hours, isn't interesting if scripts regenerated on each request.

and finally, if using cdn things jquery, (depends on if public or intranet) 4.0 , 4.5 version makes easier tell scriptmanager use cdn , fallback when cdn down.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -