开发者

Variables in URI for jQuery / Javascript

开发者 https://www.devze.com 2023-01-18 03:20 出处:网络
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.

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 usi开发者_StackOverflow中文版ng a CDN, say, Google for jQuery, how does the version variable work in the URI? Yes, I understand how $_GET works in PHP, but how does this work for a non-server-side script?

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. The fact that the file ends with .js is a mere convention. It does not guarantee that the content is javascript at all. 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. So even accessing a jquery.js?version=1.4.2 doesn't mean it will actually hit this file precise. 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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消