简体   繁体   English

在启动global.asax时填充javascript模板

[英]Populate javascript template at startup global.asax

I use asp.net mvc & going to build javascript files at application startup depending on site configuration. 我使用asp.net mvc并根据站点配置在应用程序启动时构建javascript文件。

I am going to have some javascript file templates that will be populated with appropriate constants and put into /scripts folder. 我将要准备一些javascript文件模板,这些模板将使用适当的常量填充并放入/ scripts文件夹。

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"); application_startup(){字符串populatedFile = Html.RenderPartial(“ / scripts / script.template.js”); write populatedFile into /scripts folder... } 将populatedFile写入/ scripts文件夹...}

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. 我将逻辑放在ASHX处理程序中,而不是Global.asax中,然后将ASHX作为脚本参考引用到您的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. 我将使用阅读器拉出您的模板,并使用String Builder创建最终脚本。

If the configuration is not going to change that much, make sure you are caching your output. 如果配置不会发生太大变化,请确保要缓存输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM