简体   繁体   中英

Convert JavaScript file into dll file

I have a project with Visual Studio 2012 and i have Java Script files, and CSS files in this project.
I want to make all JavaScript files as DLLs and CSS files as DLLs just like my C# Code.
Is that could be done ?, And with what tool ?
And if I'm working with bundles it will still can read from it?
Any help will be appreciated, Thanks.

You can do this for JavaScript but not css using VisualStudio. You need to add your js files as Embedded resource and then reference them in your code.

thisMSDN article goes into details but basically

  1. You add the file as an embedded resource thought VS
  2. Use ScriptManager.RegisterStartupScript to register it
  3. Add a web resource attribute [assembly: System.Web.UI.WebResource("SampleControl.UpdatePanelAnimation.js", "application/x-javascript")]

Personally I wouldn't recommend it . It makes the JavaScript horrible to debug, it prevents client side caching and it forces you to rebuild your site if you need to change the javaScript. I'd simply add a <script> tag, like everyone's always done.

MSDN article on style sheet resources but basically it just references it using a link tag, so it's not the same as above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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