如何从使用 gzip 编码的服务器在 Rhino 中加载 javascript 库?

发布于 2024-11-05 20:54:01 字数 1493 浏览 5 评论 0原文

在 rhino 中,我习惯于能够从 URL 加载 javascript 库,例如

load('http://latex.mathoverflow.net/mathjax/MathJax.js')

(这实际上不起作用,除非您首先通过 env.js 或类似的方式提供类似浏览器的环境。但是 rhino 设法获取文件,然后开始编译它。)

但是,如果服务器提供了压缩的 javascript 库,rhino 似乎会立即失败并出现语法错误,例如

load('http://cdn.mathjax.org/mathjax/latest/MathJax.js')

您可以使用curl 看到差异,例如

curl --head http://latex.mathoverflow.net/mathjax/MathJax.js

Gives

HTTP/1.1 200 OK
Date: Mon, 09 May 2011 21:07:53 GMT
Server: Apache
Last-Modified: Fri, 07 Jan 2011 05:13:36 GMT
ETag: "24b8044-9db7-4993aae2a4000"
Accept-Ranges: bytes
Content-Length: 40375
Vary: Accept-Encoding
Content-Type: application/javascript

while

curl --head http://cdn.mathjax.org/mathjax/latest/MathJax.js

Gives

HTTP/1.0 200 OK
Server: nginx
Date: Sun, 08 May 2011 20:06:19 GMT
Content-Type: application/javascript
Last-Modified: Sun, 13 Mar 2011 17:30:00 GMT
ETag: "3f59e66-a250-49e608b6bf600"-gzip
Accept-Ranges: bytes
Content-Encoding: gzip
Cache-Control: max-age=86400
Content-Length: 12466
Age: 3624
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: d0e2d89a0d90c9b7bb49b466e233b005389f96db378543b01de51769589f84dfd9733430f773846f
Via: 1.0 fee706bb2dcbccabb9a09a17e9d6037c.cloudfront.net:11180 (CloudFront), 1.0 6d5d46d2c7dcee5d4601d83b29b92a90.cloudfront.net:11180 (CloudFront)
Connection: close

有什么建议吗?有没有什么技巧可以让rhino加载gzip压缩的脚本?

In rhino, I'm used to being able to load javascript libraries from a URL, e.g.

load('http://latex.mathoverflow.net/mathjax/MathJax.js')

(This doesn't actually work, unless you provide a browser-like environment first, via env.js or similar. But rhino manages to get the file, and start compiling it.)

However, if the server provides the javascript library gzipped, rhino seems to fail immediately with syntax errors, e.g.

load('http://cdn.mathjax.org/mathjax/latest/MathJax.js')

You can see the difference using curl, e.g.

curl --head http://latex.mathoverflow.net/mathjax/MathJax.js

gives

HTTP/1.1 200 OK
Date: Mon, 09 May 2011 21:07:53 GMT
Server: Apache
Last-Modified: Fri, 07 Jan 2011 05:13:36 GMT
ETag: "24b8044-9db7-4993aae2a4000"
Accept-Ranges: bytes
Content-Length: 40375
Vary: Accept-Encoding
Content-Type: application/javascript

while

curl --head http://cdn.mathjax.org/mathjax/latest/MathJax.js

gives

HTTP/1.0 200 OK
Server: nginx
Date: Sun, 08 May 2011 20:06:19 GMT
Content-Type: application/javascript
Last-Modified: Sun, 13 Mar 2011 17:30:00 GMT
ETag: "3f59e66-a250-49e608b6bf600"-gzip
Accept-Ranges: bytes
Content-Encoding: gzip
Cache-Control: max-age=86400
Content-Length: 12466
Age: 3624
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: d0e2d89a0d90c9b7bb49b466e233b005389f96db378543b01de51769589f84dfd9733430f773846f
Via: 1.0 fee706bb2dcbccabb9a09a17e9d6037c.cloudfront.net:11180 (CloudFront), 1.0 6d5d46d2c7dcee5d4601d83b29b92a90.cloudfront.net:11180 (CloudFront)
Connection: close

Any suggestions? Is there a trick to allow rhino to load gzipped scripts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏尔 2024-11-12 20:54:01

现在有一个针对此问题的错误报告

There is now a bug report for this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文