2

I am relatively new to Visual Studio Development and I was wondering - it seems that everytime I make changes to my JS or CSS in my project - I have to "build" the project again.

Is there any way to simply refresh the browser as opposed to building everytime ? My understanding is that all the files are copied to some temporary directory but I was hoping that I can quickly debug/write JS and CSS within the solution and just refresh the browser to see the changes ?

Andy
  • 131

2 Answers2

6

In my experience, all you need to do is save the CSS/JS files and refresh the browser (hard refresh, not using the browser cache).

The reasons this will not work can be many, but mostly to do with any processing that the files need to go through before the go to the browser - say bundling, minification, usage of ScriptManager or any such server side work (including required deployment) on the files before they are available to the browser.


After chat, we confirmed that the OP is using ScriptManager with CSS/JS, causing the issue.

It is possible that using bundling instead would solve this.

Oded
  • 53,734
-2

JavaScript files are not compiled, they are interpreted. Visual Studio does not do that either, the browser does. It is done on Client browser and not the server. JS files like CSS, images and other content are cached in one or more places to save fetching time. So when the resources are being loaded the browser checks the cache first and if it is found it will not fetch it from the server. That is useful but can be problematic when developing, since you want to keep seeing your changes or images you just changed. To force the browser reload everything you can do Ctrl+F5 (hard refresh). That works for development purposes but when a new css is uploaded the users do not do a hard refresh. So if you want to ensure the users do get the latest css for example, there is a trick to do that. You add a ? and then a version number. Since this name along with that is stored in cache, when the cache is being recalled and the marker does not match the cache assumes it is new file. That also works with images and any other file. src=myCSSfile.css?ver=2018101