0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Additonal in the case of google or other big script providers: I am pretty sure that they do not use a default webserver config. Over HTTP, the server gets the information that e.g. "/script/jquery.js?version=1.4.2" is requested. The server is free to do whatever it wants with the url (think about an server generated 404 message. The server delivers content which is not associated with the requested url). So it is very easy to map such an url to a specific static file. With serverscripts you can achieve the same, but with the cost of additional scripts that are being called to resolve the url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.