如何在 Visual Studio 中调试时强制 Chrome 浏览器重新加载 .css 文件? [英] How to force Chrome browser to reload .css file while debugging in Visual Studio?

查看:32
本文介绍了如何在 Visual Studio 中调试时强制 Chrome 浏览器重新加载 .css 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 Visual Studio 2012 中编辑 .css 文件(在调试模式下).我使用 Chrome 作为我的浏览器.当我在 Visual Studio 中更改我的应用程序的 .css 文件并保存时,刷新页面不会加载我的 .css 文件中的更新更改.我认为 .css 文件仍在缓存中.

I'm currently editing a .css file inside of Visual Studio 2012 (in debug mode). I'm using Chrome as my browser. When I make changes to my application's .css file inside of Visual Studio and save, refreshing the page will not load with the updated change in my .css file. I think the .css file is still cached.

我试过了:

  1. CTRL/F5
  2. 在 Visual Studio 2012 中,转到项目属性,Web 选项卡在启动操作部分选择启动外部程序粘贴或浏览到 Google Chrome 的路径(我的是 C:UsersxxxAppDataLocalGoogleChromeApplicationchrome.exe)在命令行参数框中输入 -incognito
  3. 使用 Chrome 开发者工具,点击齿轮"图标,选中禁用缓存".

除非我手动停止调试,(关闭 Chrome),重新启动应用程序(在调试中),否则似乎什么都不起作用.

Nothing seems to work unless I manually stop debugging, (close out of Chrome), restart the application (in debug).

有没有办法强制 Chrome 始终重新加载所有 css 更改并重新加载 .css 文件?

Is there any way to force Chrome to always reload all css changes and reload the .css file?

更新:
1. 当我刷新时,我的 .aspx 文件中的内嵌样式更改会被拾取.但是 .css 文件中的更改不会.2. 它是一个 ASP.NET MVC4 应用程序,所以我单击一个超链接,它执行 GET.这样做,我没有看到对样式表的新请求.但是点击 F5,.css 文件被重新加载并且状态代码(在网络选项卡上)是 200.

Update:
1. In-line style changes in my .aspx file are picked up when I refresh. But changes in a .css file does not. 2. It is an ASP.NET MVC4 app so I click on a hyperlink, which does a GET. Doing that, I don't see a new request for the stylesheet. But clicking F5, the .css file is reloaded and the Status code (on the network tab) is 200.

推荐答案

有更复杂的解决方案,但一个非常简单的解决方案就是在 CSS 包含中添加一个随机查询字符串.

There are much more complicated solutions, but a very easy, simple one is just to add a random query string to your CSS include.

比如src="/css/styles.css?v={random number/string}"

如果您使用的是 php 或其他服务器端语言,您可以使用 time() 自动执行此操作.所以它会是 styles.css?v=<?=time();?>

If you're using php or another server-side language, you can do this automatically with time(). So it would be styles.css?v=<?=time();?>

这样,查询字符串每次都会是新的.就像我说的,有更复杂、更动态的解决方案,但出于测试目的,这种方法是顶级的 (IMO).

This way, the query string will be new every single time. Like I said, there are much more complicated solutions that are more dynamic, but in testing purposes this method is top (IMO).

这篇关于如何在 Visual Studio 中调试时强制 Chrome 浏览器重新加载 .css 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆