简体   繁体   English

jQuery / Javascript的URI中的变量

[英]Variables in URI for jQuery / Javascript

I'm sure this is a very dumb question, but I haven't been able to find any good explanations regarding what I am confused about. 我敢肯定这是一个非常愚蠢的问题,但是对于我所困惑的事情,我还没有找到任何好的解释。

When using a CDN, say, Google for jQuery, how does the version variable work in the URI? 当使用CDN(例如Google for jQuery)时,版本变量如何在URI中起作用? Yes, I understand how $_GET works in PHP, but how does this work for a non-server-side script? 是的,我了解$ _GET在PHP中的工作原理,但是对非服务器端脚本又如何工作呢?

Thanks in advance. 提前致谢。

You have several possibilities to have this feature actually. 您实际上有几种可能性可以使用此功能。

First, you could simply configure a part of your server structure to process files with slightly different rules. 首先,您可以简单地配置服务器结构的一部分来处理规则略有不同的文件。 You can imagine a folder where all .js files are actually sent to a PHP script or a CGI for processing. 您可以想象一个文件夹,其中所有.js文件实际上都发送到PHP脚本或CGI进行处理。 The fact that the file ends with .js is a mere convention. 文件以.js结尾的事实只是一个约定。 It does not guarantee that the content is javascript at all. 它根本不能保证内容是javascript。 The processing script would read the query params and send back the appropriate data to the client. 处理脚本将读取查询参数,并将适当的数据发送回客户端。 A bit convoluted, but it could work. 有点令人费解,但它可以工作。

Second, with URL rewriting, you can pretty much do what you want. 其次,通过URL重写,您几乎可以做您想做的事情。 So even accessing a jquery.js?version=1.4.2 doesn't mean it will actually hit this file precise. 因此,即使访问jquery.js?version = 1.4.2也并不意味着它将精确地命中该文件。 It can be redirected to a processing script and be totally transparent to the client. 它可以重定向到处理脚本,并且对客户端完全透明。 This technique is used extensively in wordpress to get clean and SEO friendly URLs for instance. 例如,该技术广泛用于wordpress中,以获取干净且SEO友好的URL。 Probably the best option if you are looking to implement this yourself. 如果您希望自己实现这一点,可能是最好的选择。 mod_rewrite is a bit tricky to learn but the profits you can reap are worth it. mod_rewrite学习起来有些棘手,但是您可以收获的利润是值得的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM