visual studio not updating html / javascript to server / browser
Asked Answered
S

12

37

This is an MVC 4 app using the Hot Towel SPA template. Whenever I change anything in the HTML and/or javascript the only way I can get the new code to display is to clear the browser cache. F5, cntrl-F5, shift-F5, nothing works.

I'm not normally a web dev and just learning this. I've done regular MVC before and not had this issue, maybe it has to do with where the HTML and javascript is in my project (i.e. in the /App folder) ?. I'm going nuts trying to figure this out.

I can completely delete an HTML file and run the app and it still runs as it did. Clear cache and run and I then get the update.

It's running using IIS express using Firefox, Chrome, IE...

Thanks..

Sinfonietta answered 26/3, 2013 at 20:10 Comment(0)
A
52

In Opera and Chrome (and possibly others), you can disable caching while in 'development mode'.

While in DevTools, the 2nd option in the Settings menu is

Disable cache (while DevTools is open)

Alhambra answered 1/7, 2015 at 4:1 Comment(2)
This only solves the problem if the issue is on the browser side (which I previously faced also) but not if the issue is somewere in between the angular-.net saving changed filesVioloncellist
In Chrome 101.X on Windows, this option is in Preferences -> Network and is the 4th option.Ogrady
M
22

I also experienced this issue and turns out it was related to caching.

If using Chrome DevTools, you can simply disable cache by navigating to the Network Tab and ticking Disable Cache

This will only disable the cache when Dev Tools is open.

Maros answered 22/2, 2017 at 19:58 Comment(1)
This really helped and in my opinion should be marked as correct solutionOctane
R
19

Go to your web.config file and make a change in it.Its not matter what change you make.For example type a character and then delete it and build the project and run it again.I hope it works.

Rabbit answered 26/3, 2013 at 20:17 Comment(5)
Please rather accept this as an answer. Turning off caching in your browser is not great for when you are browsing outside of developmentGobioid
This does not work for me, still the old *.js files in "dynamic" are loaded and executed. The only effect is that VS forces you to restart the debug session.Chiclayo
This worked for me although I had tried everything elseSplenetic
i did that, but still have issue. no changes i see on live website.Hammered
after hours of trying to solve this, this solution came closest. however, once i turn cache on again, i still get the wrong page. any ideas??Roesch
W
8

ctrl+shift+F5 will do the trick! Seems like browser cache is part of the problem :)

Walk answered 16/4, 2015 at 8:50 Comment(0)
T
7

in my case iis express not updated site, but site , created by iis Manager worked correctly?

possible solution for this problem is set "use this 64 bit version of iis express for web sites and projects" option at visual studio it located at options->Projects and Solutions->Web projects

Tyrannous answered 21/1, 2016 at 9:23 Comment(0)
T
6

I found that I had the .js file open in the Chrome Developer Tools -> Sources View.

When I closed the file there and refreshed the page the new .js file showed up as expected.

Taxiplane answered 26/8, 2016 at 13:3 Comment(1)
this wasmy issue but why? i did refreshed the page when it was open maybe chrome tools is not updating the file?Eventide
R
6

I had an issue with moved .ts & .html files on the server and had to:

  1. stop debugging
  2. clear the whole output/dist folder inside my ClientApp
  3. start debugging again
  4. Ctrl-F5 to force the cache to refresh on the browser

Simply disabling the browser's cache, or forcing the .net app to recompile, or even running ng serve had no effect.

Rior answered 26/11, 2018 at 23:46 Comment(0)
C
5

The browsers cache by default. You can turn off caching in your browser to get the changed files.

Cataplexy answered 26/3, 2013 at 23:31 Comment(2)
See other solution from Hamid, this answer is only good for temporarily recache things, however caching should be turned back on.Wende
this answer is for when developing. under develop this setting should always be onCataplexy
P
3

None of the above listed methods works consistently and if one considers that different browsers are used in the task pane depending on Windows version/build used then you may have to clear the cache of a different browser in each case.

However, it seems that the real issue is not so much browser caching as it is VS deciding which files to deploy to the local IIS Express server used for testing/development. In many cases, when pressing the "Start" button, modified html and/or js files won't make it to the local deployment even if you also modify the web.config file.

The way I made this work consistently is I selected the web application project (in Solution Explorer), opened properties, clicked the "Package/Publish Web" tab and then under "Items to deploy" I selected "All files in this project".

Works fine for me!

Poetics answered 5/6, 2020 at 6:47 Comment(1)
Didn't work at first, because I needed to clear cache after I made this change in project properties. But now when I change .js file, it works automatically without needing to clear cache all the time. Thank you for this !Genevagenevan
B
3

Following are some of the options that we can use to solve the problem.

  • ctrl + shift + r (This will do a hard refresh of your current tab)
  • ctrl + F5 (This will force the cache to refresh on the browser)
  • Stop debugging and Change the web.config file and run again
  • Stop debugging and clean the project, Rebuild it and run the project
Bronchiole answered 22/4, 2022 at 17:45 Comment(0)
P
1

If you just want to test locally You can try

A) Create Virtual Directory Follow below path: Project / Properties / Web
Find Servers section Click on Create Virtual directory

B) Follow below path: Project / Properties / Web
Find Servers section Click on Drop down and change the selected value between Express and Local Then Create Virtual directory

Peroneus answered 19/11, 2018 at 21:28 Comment(0)
D
0

In case disabling the cache and editing the web.config file does not work.

Simply close the solution and reopen it and try it. Strange, but it worked for me.

Dustproof answered 28/8, 2017 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.