我有以下问题,来自摩根日志:
Tue, 18 Sep 2018 10:50:26 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:26 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:30 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:30 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:30 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:32 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:32 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:32 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:33 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:33 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:33 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:35 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:35 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:35 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:38 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:38 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:38 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:40 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:40 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:40 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:44 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:44 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:44 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:49 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:49 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:49 GMT GET /public/img/shield_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:51 GMT GET /public/img/healthpack_powerup.png - ::ffff:127.0.0.1 200
Tue, 18 Sep 2018 10:50:51 GMT GET /public/img/speedboost_powerup.png - ::ffff:127.0.0.1 200
Yeap, same files being req. and loaded over and over.
From browser console:
-
请求方法:GET
-
状态代码:200 OK
-
远程地址:127.0.0.1:443
-
推荐人政策:no-referrer-when-downgrade
-
Accept-Ranges:bytes
-
Cache-Control:public,max-age = 0
-
连接:保持活着
-
内容长度:2163
-
Content-Type:image / png
-
日期:星期二,2018年9月18日,格林威治标准时间11:45:39
-
ETag:W / "873-165340ec190"
-
最后修改时间:周一,2018年8月13日16:11:46 GMT
-
X-Powered-By:快递
-
接受:image / webp,image / apng,image /,/ *; q = 0.8
-
Accept-Encoding:gzip,deflate,br
-
接受语言:es-419,es; q = 0.9,en-GB; q = 0.8,en; q = 0.7
-
连接:保持活着
Cache-Control:public,max-age = 0,max-age = 0看起来不太好 .
-
图像(异步)
-
Drawing.drawPowerup @ Drawing.js:175
-
Game.draw @ Game.js:232
-
Game.run @ Game.js:96
-
(匿名)@ base.js:32
So.. Drawing:175
Drawing.prototype.drawPowerup = function(coords, name) {
this.context.save();
this.context.translate(coords[0], coords[1]);
var powerup = new Image();
powerup.src = Drawing.BASE_IMG_URL + name + '.png';
this.context.drawImage(powerup, -powerup.width / 2, -powerup.height / 2);
this.context.restore();
};
来源是Drawing.BASE_IMG_URL名称'.png';这意味着...... /public/img/shield_powerup.png
公共文件夹似乎在执行缓存时失败,这是如何(服务器):
-
// espacios publicos
-
app.use('/public',express.static(__ dirname '/public'));
-
app.use('/shared',express.static(__ dirname '/shared'));
No cache. Heres's my first attemp:
-
// espacios publicos
-
app.use('/public',express.static(__ dirname '/public'),{maxAge:30000});
-
app.use('/shared',express.static(__ dirname '/shared'),{maxAge:30000});
我什么时候:
$ node server.js --dev --free
C:\Users\xxxxx\xxxxx\xxxxx\xxxxx\node_modules\express\lib\router\index.js:458
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^
TypeError: Router.use() requires a middleware function but got a Object
at Function.use (C:\Users\xxxxx\xxxxx\xxxxx\xxxxx\node_modules\express\lib\router\index.js:458:13)
at EventEmitter.<anonymous> (C:\Users\xxxxx\xxxxx\xxxxx\xxxxx\node_modules\express\lib\application.js:220:21)
at Array.forEach (native)
at EventEmitter.use (C:\Users\xxxxx\xxxxx\xxxxx\xxxxx\node_modules\express\lib\application.js:217:7)
at Object.<anonymous> (C:\Users\xxxxx\xxxxx\xxxxx\xxxxx\server.js:116:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Does anyone know what I'm doing wrong? I'm exhausted
另外,我以不同的方式接近:
-
const cacheTime = 86400000 * 30; //你想要的时间
-
const path = require('path');
-
// espacios publicos
-
app.use(express.static(path.join(__ dirname,'public'),{maxAge:cacheTime}))
-
app.use(express.static(path.join(__ dirname,'shared'),{maxAge:cacheTime}))
然而,哪个有效,有很多错误:
127.0.0.1/:1 Refused to apply style from 'https://127.0.0.1/public/bower/bootstrap/dist/css/bootstrap.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
127.0.0.1/:1 Refused to apply style from 'https://127.0.0.1/public/dist/minified.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
127.0.0.1/:1 Refused to execute script from 'https://127.0.0.1/public/bower/jquery/dist/jquery.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'https://127.0.0.1/public/bower/bootstrap/dist/js/bootstrap.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'https://127.0.0.1/public/js/qrcode.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'https://127.0.0.1/public/js/sound.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'https://127.0.0.1/shared/Constants.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'https://127.0.0.1/shared/Util.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'https://127.0.0.1/shared/base.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'https://127.0.0.1/public/js/game/AFK_Kicker.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
继续使用大约60个文件 .
Any idea?
问候,克里斯
解决了问题的第一部分,但我仍然有主要问题:
//espacios publicos
app.use('/public', express.static(__dirname + '/public', { maxAge: '1d' }));
app.use('/shared', express.static(__dirname + '/shared', { maxAge: '1d' }));
Now it doesn't make any sense to me...
-
请求方法:GET
-
状态代码:200 OK
-
远程地址:127.0.0.1:443
-
推荐人政策:no-referrer-when-downgrade
-
Accept-Ranges:bytes
-
Cache-Control:public,max-age = 86400
-
连接:保持活着
-
内容长度:1987
-
Content-Type:image / png
-
日期:星期二,2018年9月18日格林威治标准时间13:09:26
-
ETag:W / "7c3-165340ec18f"
-
最后修改时间:周一,2018年8月13日16:11:46 GMT
-
X-Powered-By:快递
-
接受:image / webp,image / apng,image /,/ *; q = 0.8
-
Accept-Encoding:gzip,deflate,br
-
接受语言:es-419,es; q = 0.9,en-GB; q = 0.8,en; q = 0.7
-
连接:保持活着
-
Cookie:xxx
-
主机:127.0.0.1
-
Referer:https://127.0.0.1/
-
User-Agent:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 69.0.3497.92 Safari / 537.36
~2 Sec later ~
-
请求方法:GET
-
状态代码:200 OK
-
远程地址:127.0.0.1:443
-
推荐人政策:no-referrer-when-downgrade
-
Accept-Ranges:bytes
-
Cache-Control:public,max-age = 86400
-
连接:保持活着
-
内容长度:1987
-
Content-Type:image / png
-
日期:星期二,2018年9月18日格林威治标准时间13:09:26
-
ETag:W / "7c3-165340ec18f"
-
最后修改时间:周一,2018年8月13日16:11:46 GMT
-
X-Powered-By:快递
-
接受:image / webp,image / apng,image /,/ *; q = 0.8
-
Accept-Encoding:gzip,deflate,br
-
接受语言:es-419,es; q = 0.9,en-GB; q = 0.8,en; q = 0.7
-
连接:保持活着
-
Cookie:xxx
-
主机:127.0.0.1
-
Referer:https://127.0.0.1/
-
User-Agent:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 69.0.3497.92 Safari / 537.36
As you can see Chrome keeps asking for the files, even when:
Same ETag + MaxAge in 1 day.