简体   繁体   English

网络上的本地主机-通过网络访问时缓存CSS文件且未更新CSS文件

[英]Localhost over network - CSS files being cached and not updated when accessing over network

So I am trying to figure out why my localhost app looks different when accessed from another computer, as opposed to the way it looks when I am accessing my localhost directly from my machine. 因此,我试图弄清为什么我的本地主机应用程序在从另一台计算机访问时看起来有所不同,而不是直接从我的计算机访问本地主机时的外观。

I am using a WAMPSERVER and I have a PHP app. 我正在使用WAMPSERVER,并且有一个PHP应用程序。 It seems like when I try and change the CSS of the app, only I can see the changes. 似乎当我尝试更改应用程序的CSS时,只有我可以看到更改。 When I try and access the app through another machine, by accessing my localhost, the app looks different and some of the styling is the old styling. 当我尝试通过另一台机器访问该应用程序时,通过访问我的本地主机,该应用程序看起来有所不同,其中某些样式是旧样式。 Also, if I change anything in the HTML, it updates correctly, but I cannot seem to be able to change the CSS - almost as if the network cached the CSS and it won't update it anymore. 另外,如果我更改了HTML中的任何内容,则它可以正确更新,但似乎无法更改CSS-几乎就像网络缓存了CSS一样,它也不再更新。

I tried: 我试过了:

  1. restarting the WAMPSERVER 重新启动WAMPSERVER
  2. clearing browser cache 清除浏览器缓存
  3. restarting the PC 重新启动电脑
  4. Flushing DNS cache ( ipconfig /flushdns ) 刷新DNS缓存(ipconfig / flushdns)

Nothing seems to be working and the only way I can affect the style of the page is by adding inline CSS which is a pain in the butt and I do not want to do that. 似乎没有任何效果,并且可以影响页面样式的唯一方法是添加内联CSS,这很麻烦,我也不想这样做。

Any suggestions will be highly appreciated! 任何建议将不胜感激!

如果您使用的是PHP Framework(Zend,Symfony等),则其中许多都包含了自己的缓存,并且由于您不是从本地地址访问站点,而是自动使用缓存,因此您可能需要清除框架的缓存。

Browsers cache things, and that can be boring. 浏览器缓存事物,这可能很无聊。

A way to prevent that is to add a random string in the url where you get your CS, JS, or whatever, like that : 一种防止这种情况的方法是在获得CS,JS或类似内容的网址中添加随机字符串:

<link href="mystyle.css?t=<?php echo time()?>" rel="stylesheet" type="text/css" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM