asp.net mvc - A localized scriptbundle solution -
hi using asp.net mvc 4 rc system.web.optimization. since site needs localized according user preference working jquery.globalize plugin.
i want subclass scriptbundle class , determine files bundle according system.threading.thread.currentthread.currentuiculture
. this:
bundles.add(new localizedscriptbundle("~/bundles/jqueryglobal") .include("~/scripts/jquery.globalize/globalize.js") .include("~/scripts/jquery.globalize/cultures/globalize.culture.{0}.js", () => new object[] { thread.currentthread.currentuiculture }) ));
for example if ui culture "en-gb" following files picked (minified of course , if possible cached aswell until script file or currentui culture changes).
- "~/scripts/jquery.globalize/globalize.js"
- "~/scripts/jquery.globalize/globalize-en-gb.js" <-- if file not exist on sever file system fallback globalize-en.js.
i tried overloading include method following wont work because not evaluated on request on startup of application.
public class localizedscriptbundle : scriptbundle { public localizedscriptbundle(string virtualpath) : base(virtualpath) { } public bundle include(string virtualpathmask, func<object[]> getargs) { string virtualpath = string.format(virtualpathmask, getargs()); this.include(virtualpath); return this; } }
thanks
constantinos
that correct, bundles should configured pre app start. otherwise in multi server scenario, if request bundle routed different server other 1 served page, request bundle resource not found.
does make sense? of bundles need configured , defined in advance, , not dynamically registered on per request basis.
Comments
Post a Comment