在带有webpacker replaced by sprockets的Rails6应用中,我无法让链轮使我的浏览器缓存字体。 编辑:我的浏览器确实缓存了字体,但是谷歌抱怨并卷曲显示了应用程序的响应方式(<< 304>并没有达到预期,请参见下文)。字体例如 。gzapp/assets/fonts/OTF/SourceSansPro-BoldIt.otf
,并正确放入public/assets/OTF/...fingerprint...
(并带有font-url()
)。curl
时,我似乎永远都不会获得HTTP/1.1 304 Not Modified
,但会获得具有给定有效负载的200
。与其他(JS,CSS)资产一样,它可以按预期工作。
我没有修改config/initializers/assets.rb
,因为应该已经拾取了所有子目录和文件(assets:precompile
的输出和public/assets
的内容表明它可以正常工作。]
挖掘https://github.com/rails/sprockets/blob/9909da64595ddcfa1e7ee40ed1d99738961288ec/lib/sprockets/server.rb#L73处的链轮代码似乎表明etag设置不正确或类似的设置,但是我并没有真正修改该代码。
据我所知,该应用程序是使用具有相当标准的nginx配置的dokku(基本上是heroku)进行部署的。该应用程序自行提供资产(例如在heroku中)。
[我该怎么做,以便链轮添加相关的标题/用https://github.com/dokku/dokku/blob/master/plugins/nginx-vhosts/templates/nginx.conf.sigil“正确”响应?任何想法如何调试该问题?
相关的“调试”部分
304
随后获取CSS
If-Modified-Since:Mon,06 Apr 2020 11:59:56 GMT标头。curl -v https://...application-3d...c76c3.css \
-H 'Accept: text/css,*/*;q=0.1'\
-H 'Accept-Language: en-US,en;q=0.5'\
--compressed # omitted: ... User-Agent, DNT, ...
# omitted: TLS handshake etc
> GET /assets/application-3d...c76c3.css HTTP/1.1
> Host: #the host
> Accept-Encoding: deflate, gzip
> User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0
> Accept: text/css,*/*;q=0.1
> Accept-Language: en-US,en;q=0.5
> Referer: #the host
> DNT: 1
> Connection: keep-alive
> Cookie: #a cookie
>
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 21 Apr 2020 15:39:47 GMT
< Content-Type: text/css
< Content-Length: 41256
< Connection: keep-alive
< Last-Modified: Mon, 06 Apr 2020 11:59:56 GMT
< Content-Encoding: gzip
< Vary: Accept-Encoding
<
# payload
(这就是我想要的:A对字体资产的初始请求304未修改
。
curl -v 'https://.../assets/application-3d...c76c3.css' \
-H 'If-Modified-Since: Mon, 06 Apr 2020 11:59:56 GMT'\
-H 'Cache-Control: max-age=0'
> If-Modified-Since: Mon, 06 Apr 2020 11:59:56 GMT
> Cache-Control: max-age=0
>
< HTTP/1.1 304 Not Modified
< Server: nginx
< Date: Tue, 21 Apr 2020 15:50:52 GMT
< Connection: keep-alive
随后获取字体
curl -v 'https://.../assets/WOFF2/TTF/SourceSansPro-Light.ttf-32...d9.woff2' \
-H 'Accept: application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8'\
-H 'Accept-Language: en-US,en;q=0.5'\
--compressed \
-H 'Referer: https://...assets/application-3d....c76c3.css'
# ommitted: User Agent, Cookies, ....
> GET /assets/WOFF2/TTF/SourceSansPro-Light.ttf-32...d9.woff2 HTTP/1.1
> Host: #the host
> Accept-Encoding: deflate, gzip
> User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0
> Accept: application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8
> Accept-Language: en-US,en;q=0.5
> DNT: 1
> Connection: keep-alive
> Referer: https://.../assets/application-3d...c76c3.css
# cookie etc
>
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 21 Apr 2020 15:45:34 GMT
< Content-Type: application/font-woff2
< Content-Length: 88732
< Connection: keep-alive
< Last-Modified: Wed, 25 Mar 2020 20:09:14 GMT
<
# payload
我发现很有趣,服务器实际上发送了一个Last-Modified