Chrome不会缓存CSS文件。 .js文件可以正常工作

时间:2018-08-16 13:05:31

标签: .net google-chrome caching iis web-config

Chrome不会在我的网站上缓存CSS文件,js文件也可以毫无问题地缓存,但是每次都会从服务器加载CSS。 服务器是IIS 8,在我的web.config中,我有:

  <location path="Content/dist">
<system.webServer>
  <staticContent>
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:15" />
  </staticContent>
</system.webServer>
     

设置缓存在1天后过期。在我的CSS文件的标头中,我看到它已经被采用了,

  

缓存控制:max-age = 86415

完整的标头如下:

Accept-Ranges: bytes
Cache-Control: max-age=86415
Content-Encoding: gzip
Content-Length: 78464
Content-Type: text/css
Date: Thu, 16 Aug 2018 11:46:30 GMT
ETag: "053689a4935d41:0"
Last-Modified: Thu, 16 Aug 2018 10:12:14 GMT
Server: Microsoft-IIS/8.5
Vary: Accept-Encoding
X-Powered-By: ASP.NET

在我的本地计算机上,按预期从高速缓存中读取文件,但是当我将其推送到服务器时,却出现了麻烦的行为。这只是发生的CSS,web.config中引用的同一文件夹中的.js文件正在从缓存中加载。这是一个这样的文件的标题。

Accept-Ranges: bytes
Cache-Control: max-age=86415
Content-Encoding: gzip
Content-Length: 3698
Content-Type: application/javascript
Date: Thu, 16 Aug 2018 11:45:44 GMT
ETag: "f7e1df9a4935d41:0"
Last-Modified: Thu, 16 Aug 2018 10:12:14 GMT
Server: Microsoft-IIS/8.5
Vary: Accept-Encoding
X-Powered-By: ASP.NET

Firefox也按照我的期望从缓存中加载文件。

https://gyazo.com/3ba41707c00e7fb539f6b84cc90f70e0

网站网址:

https://devworks.cashbackforex.com/

1 个答案:

答案 0 :(得分:2)

我遇到了类似的问题,结果是web.config的编制属性设置为debug = true,就像-

from django.core.management.base import BaseCommand from django.db import IntegrityError from django.contrib.contenttypes.models import ContentType from django.utils.translation import ugettext_lazy as _ from django.conf import settings from GeneralApp import models class Command(BaseCommand): help = _("""Run this commando to populate an empty database with initial data required for Attractora to work. For the momment, this models are considered on 'populate_db' command: - InventoriManagerApp.InventoryManagerAppActions """) def populate_db(self): applications = settings.INSTALLED_APPS for application in applications: try: import applications.models except: pass #from InventoryManagerApp.models import InventoryManagerAppActions models_to_populate = (vars()['AppModelActions']) #models_to_populate = (InventoryManagerAppActions,) for model_to_populate in models_to_populate: self.populate_model('InventoryManagerApp', model_to_populate) def populate_model(self, app_label, model_to_populate): model_to_populate_instance = model_to_populate() content_type = ContentType.objects.get(app_label=app_label, model=model_to_populate_instance.name) if hasattr(model_to_populate_instance, 'populate_data'): populate_data = model_to_populate.populate_data for record in populate_data: for key, value in record.items(): setattr(model_to_populate_instance, key, value) try: model_to_populate_instance.save() except IntegrityError: print("{} already exists.".format(model_to_populate_instance)) # else: # new_permission = Permission.objects.create(code_name=) def handle(self, *args, **kwargs): self.populate_db()

这将导致您的文件既不捆绑也不缓存在浏览器上。只是删除debug = true解决了我的问题。所以我将其更改为-

<compilation debug="true"></compilation>

编辑-

特别是对于Chrome,它可能与您的证书有关。

Chrome不会从具有自签名证书的服务器中缓存资源

See here

相关问题