Razor syntax in Javascript files

    I don't always mix server side code with client side code... but continuing with my thoughts on server and client models. I wanted to know if I could use razor syntax in a javascript file. Which means I woud be able take advantage of the Asp.net Bundling and Minification feature. Now I probably didn't bring this approach up in the article but what I did talk about was using query url with the javascript. Not being able to cache javascript files is the major reason why avoid using using it and I didn't think I would take this approach either but I did want to see if it was possible.
  In my research I did notice some loss of performance, I didn't do any benchmarking but I felt the process was a little wonky. I think the third link best describes my thoughts on this approach. So what  I have been doing now since this is using the "data" attribute and assigning a value with razor syntax. It's not completely perfect but it does have some advantages. A lot of times I don't want my data from the server to the client side be visible or indexable so that is a plus. If I want it visible or indexable what I do is pull it via javascript and output to something that I have appropriately styled.


Resources
NuGet Gallery | RazorJS 0.4.3
asp.net-mvc: razor '@' symbol in js file - Stack Overflow
Insert C# code into (.js)javascript file - Stack Overflow 
Using data attributes - Web developer guide | MDN

Popular posts from this blog

UI-Bootstrap Collapsible Sticky Footer

Installing Windows on Acer chromebook 15 cb3-532

Aspetcore: NLog with Postgresql