相关疑难解决方法(0)

如何防止Django测试服务器中的HTTP 304

我在Django有几个项目,偶尔在一个和另一个之间交替.所有这些都有一个/ media/path,由django.views.static.serve提供,它们都有一个/media/css/base.css文件.

问题是,每当我运行一个项目时,对base.css的请求都会返回HTTP 304(未修改),可能是因为时间戳没有改变.但是当我运行另一个项目时,返回相同的304,使浏览器使用前一个项目缓存的文件(因此,使用错误的样式表).

仅供记录,以下是中间件类:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.transaction.TransactionMiddleware',
)
Run Code Online (Sandbox Code Playgroud)

我总是使用默认地址http:// localhost:8000.还有其他解决方案(除了使用不同的端口 - 8001,8002等)?

django caching http-status-code-304

6
推荐指数
1
解决办法
3584
查看次数

hash css和js文件来破解缓存.它慢吗?

我有一些生成页面模板的脚本.此外,此脚本在HTML中呈现<script><link rel='stylesheet'>标记.

我想用"?v = xxxxx"参数添加缓存中断功能.

我是这样做的:

foreach ($scripts as &$script) {

    // get script file name
    $script = "{$this->_js_folder}/{$script}";

    // get it's realpath
    $realfile = realpath(substr($script,1));

    // hashing the file
    $hash = md5_file($realfile);

    // adding cache-breaking number
    $script .= '?v='.$hash;

} //: foreach
Run Code Online (Sandbox Code Playgroud)

每次用户刷新页面时,要散列大约十几个文件,这不是很慢吗?

php hash md5-file

2
推荐指数
1
解决办法
2839
查看次数

标签 统计

caching ×1

django ×1

hash ×1

http-status-code-304 ×1

md5-file ×1

php ×1