查询JavaScript文件末尾的参数 [英] query parameters at the end of the JavaScript file

查看:64
本文介绍了查询JavaScript文件末尾的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在JavaScript文件后面找到更多使用查询参数的网页




示例可以在 www.opensourcefood.com 。在源代码中你会看到:< script src =" /shared/scripts/common.js?revision = 1.6"

type =" text / javascript"> ;.


我想看看这个或者最佳实践是否有什么大不了的事情

开始爬起来在JavaScript社区中。如果这是

仅用作区分正在使用的JavaScript文件的方式

为什么不在文件中附加内容?有没有其他人看过这个

或知道更多理由这样做?

I am starting to find more web pages that are using a query parameters
after the JavaScript file.

Example can be found at www.opensourcefood.com. Within the source
you''ll see: <script src="/shared/scripts/common.js?revision=1.6"
type="text/javascript">.

I am trying to see if there is any big deal to this or a best practice
that is starting to creep up in the JavaScript community. If this is
used only as a way to distinguish what file of JavaScript being used
why not append something inside the file? Has anyone else seen this
or know of more reasons to do this?

推荐答案

8月10日,12:26 am,NeoAlchemy< NeoAlch ... @ gmail.comwrote:
On Aug 10, 12:26 am, NeoAlchemy <NeoAlch...@gmail.comwrote:

我开始找到更多使用查询参数的网页

在JavaScript文件之后。


示例可以在www.opensourcefood.com找到。在源代码中你会看到:< script src =" /shared/scripts/common.js?revision = 1.6"

type =" text / javascript">。
I am starting to find more web pages that are using a query parameters
after the JavaScript file.

Example can be found atwww.opensourcefood.com. Within the source
you''ll see: <script src="/shared/scripts/common.js?revision=1.6"
type="text/javascript">.



我根本不喜欢这样。它表明他们正在使用CGI来提供静态脚本文件。我认为它们是静态的,因为查询中唯一的

信息是版本号。有些浏览器不会使用查询字符串检索
缓存文件,所以这看起来像是一个疯狂的事情。

I don''t like that at all. It indicates that they are using CGI to
serve static script files. I assume they are static as the only
information in the query is a version number. Some browsers will not
cache files retrieved with a querystring, so this would seem like a
crazy thing to do.


我试图看看这个或最佳实践是否有什么大不了的事情

开始在JavaScript社区中悄然兴起。如果这是

仅用作区分正在使用的JavaScript文件的方式

为什么不在文件中附加内容?有没有其他人看过这个

或知道更多理由这样做?
I am trying to see if there is any big deal to this or a best practice
that is starting to creep up in the JavaScript community. If this is
used only as a way to distinguish what file of JavaScript being used
why not append something inside the file? Has anyone else seen this
or know of more reasons to do this?



有充分的理由将版本信息放在静态

脚本的文件名中(例如common_v1_0.js)以便你可以使用Expires和/

或Cache-Control标头。例如,您可以将

服务器配置为服务所有静态脚本,期限为30天

(最多一年),浏览器将缓存并重新使用它们每次页面加载
时,询问服务器上次修改时是否需要
。更新脚本时,会将版本号设置为

,以防止浏览器使用缓存的过时副本。

There is a good reason to put version info in the filename of a static
script (eg common_v1_0.js) so that you can make use of the Expires and/
or Cache-Control headers. For instance, you could configure your
server to serve all static scripts with an expiration of thirty days
(one year max) and browsers will cache and re-use them without having
to ask the server when they were last modified each time a page is
loaded. When you update a script, you bump the version number to
prevent browsers from using a cached, outdated copy.


David Mark写道:
David Mark wrote:

8月10日上午12:26,NeoAlchemy< NeoAlch ... @ gmail.comwrote:
On Aug 10, 12:26 am, NeoAlchemy <NeoAlch...@gmail.comwrote:

>我开始在JavaScript文件之后找到更多使用查询参数的网页。
示例脚本src =" /shared/scripts/common.js?修订= 1.6"
>I am starting to find more web pages that are using a query parameters
after the JavaScript file.
Example script src="/shared/scripts/common.js?revision=1.6"



我根本不喜欢这样。它表明他们正在使用CGI来提供静态脚本文件。

I don''t like that at all. It indicates that they are using CGI to
serve static script files.



这并不一定表明它正在使用CGI。您可以将

请求发送到任何标准的Web服务器,并且它将完全忽略所有内容后的所有内容

?并将始终返回相同的静态文件。它可能只是因为他们用它来跟踪哪个版本的其他

文件正在向common.js发出请求。通过一些服务器日志

处理,您可以确定例如您有50%的请求

到common.js是由版本1.6制作的,30%是由1.5

等制成。这是一种可能性。或者说1.6可能是为了表明浏览器支持哪个
版本的JavaScript(脚本

language =" JavaScript1.6")并且该网站正在使用它某种

监控浏览器统计信息。我已经用JS请求做了一件事

就是在它的末尾加上一个随机数来缓存请求

(src =''file .js?" + Math.random().....)如果您知道

文件可能随时更改并且您不想依赖浏览器

自己的缓存设置。

It''s not definitely indicating that it''s using CGI. You can send that
request to any standard web server and it will totally ignore everything
after the ? and will always return the same static file. It could be
just that they''re using it for tracking which version of a some other
file is making requests to common.js. With a bit of server log
processing you can determine for example that you have 50% of requests
to common.js are being made by version 1.6, 30% are being made by 1.5
etc etc. That''s one possibility. Or that 1.6 could be to indicate which
version of JavaScript is supported in the browser (script
language="JavaScript1.6") and the site is using it for some kind of
monitoring of browser stats. One thing I''ve done also with JS requests
is to tack onto the end of it a random number to cache-bust the request
(src=''file.js?"+Math.random() .....) which is useful if you know the
file could change at any time and you don''t want to rely on the browsers
own cache settings.


8月10日凌晨1点53分,Stevo< ple ... @ spam-me.comwrote:
On Aug 10, 1:53 am, Stevo <ple...@spam-me.comwrote:

David Mark写道:
David Mark wrote:

8月10日上午12:26,NeoAlchemy< NeoAlch。 .. @ gmail.comwrote:
On Aug 10, 12:26 am, NeoAlchemy <NeoAlch...@gmail.comwrote:

我开始在JavaScript文件之后找到更多使用查询参数的网页



示例脚本src =" /shared/scripts/common.js?revision = 1.6"
I am starting to find more web pages that are using a query parameters
after the JavaScript file.
Example script src="/shared/scripts/common.js?revision=1.6"



我根本不喜欢这样。它表明他们正在使用CGI来提供静态脚本文件。

I don''t like that at all. It indicates that they are using CGI to
serve static script files.



这并不一定表明它正在使用CGI。您可以将

请求发送到任何标准Web服务器,它将完全忽略所有内容


It''s not definitely indicating that it''s using CGI. You can send that
request to any standard web server and it will totally ignore everything



这绝对可以表明他们正在使用CGI。如果没有,那么

他们正在做一些非常愚蠢的事情。

It definitely could indicate that they are using CGI. If not, then
they are doing something really silly.


之后?并将始终返回相同的静态文件。它可能是

只是他们用它来跟踪其他一些
的版本
after the ? and will always return the same static file. It could be
just that they''re using it for tracking which version of a some other



就像那样。

Like that.


文件正在向common.js发出请求。通过一些服务器日志

处理,您可以确定例如您有50%的请求

到common.js是由版本1.6制作的,30%是由1.5

等制成。这是一种可能性。或者说1.6可能是为了表明浏览器支持哪个
版本的JavaScript(脚本

language =" JavaScript1.6")并且该网站正在使用它某种
file is making requests to common.js. With a bit of server log
processing you can determine for example that you have 50% of requests
to common.js are being made by version 1.6, 30% are being made by 1.5
etc etc. That''s one possibility. Or that 1.6 could be to indicate which
version of JavaScript is supported in the browser (script
language="JavaScript1.6") and the site is using it for some kind of



脚本元素必须动态生成。

The script element would have to be dynamically generated.


监控浏览器统计信息。我已经用JS请求做了一件事

就是在它的末尾加上一个随机数来缓存请求

(src =''file .js?" + Math.random().....)如果您知道

文件可能随时更改并且您不想依赖浏览器

拥有缓存设置。
monitoring of browser stats. One thing I''ve done also with JS requests
is to tack onto the end of it a random number to cache-bust the request
(src=''file.js?"+Math.random() .....) which is useful if you know the
file could change at any time and you don''t want to rely on the browsers
own cache settings.



这对我没用。网站上的每个页面都必须每次都下载脚本
。如果脚本是动态的,那么

应该由CGI提供适当的头文件以防止

缓存。

That makes no sense to me. Every page on the site would have to
download the script every time. If the script is that dynamic, then
it should be served by CGI with appropriate headers to prevent
caching.


这篇关于查询JavaScript文件末尾的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆