views:

43

answers:

1

Hello, everybody

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 to have something like:

application_startup() { string populatedFile = Html.RenderPartial("/scripts/script.template.js"); write populatedFile into /scripts folder... }

Thank you in advance !

A: 

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.

kim3er
Ohhh, thank you very much! What a good idea! :)I created controller that renders populated javascript files via partial views with OutputCache attribute applied to methods
Andrew Florko