Is it possible to serve js file requests that are for js files that are reource files in a c# project? And if so does serving javascript files that are embedded in dlls incur any performance hit over the traditional method of having them in the web projects scripts folder? I'm quite interested in the new OWIN katana stuff and I thought it might be possible to make my asp.net library as a single dll anyone can reference in their projects and it will be able to serve all the client side components itself without users having to import multiple files/projects.
1 Answer
Yes it is possible to embed your JS (or any other file) into a DLL. You'll need a virtual path provider, an example can be found here:
http://www.danielroot.info/2013/07/reuse-mvc-views-using-virtual-path.html
the example is about views, but its easy enough to modify it for the use of JS files.
If you Google the terms a bit you'll find more examples.
I tried it once,I must say; it wasn't worth the effort.
As for the performance impact; JS files are usually cached and optimized. Even if you retrieve the resource from within the DLL, the application will see this as a normal file request (normally) and the cache mechanism will kick in.