Populate javascript template at startup global.asax
I use asp.net mvc & going to build javascript files at application startup depending on site configuration.
I am going to have some javascript file templates that will be populated with appropriate constants and put into /scripts folder.
Please, suggest me the best way to do that. I want t开发者_如何学JAVAo have something like:
application_startup() { string populatedFile = Html.RenderPartial("/scripts/script.template.js"); write populatedFile into /scripts folder... }
Thank you in advance !
I'd look at putting the logic in ASHX handler rather than Global.asax, then reference the ASHX as a script reference in your Site Master.
With regards to the actual logic. I'd be pulling your templates using a reader and creating the final script with a String Builder.
If the configuration is not going to change that much, make sure you are caching your output.
精彩评论