简体   繁体   中英

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? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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