Reputation: 7769
I assume the browser contacts the web server and asks for the "src" (in those situations where there's something to src).
Can that interaction be controlled in any way? How much information is available to the server about who wants the src and when?
Alternatively, could one deliberately 404 the request, then control the 404 mechanism to respond appropriately?
Upvotes: 0
Views: 80
Reputation: 138100
Don't mess around with 404 handling for this. If you want to dynamically generate javascript there's no need.
The browser doesn't care what URL is in the src=""
attribute - it certainly doesn't have to end in .js
. The important thing is that whatever the URL is, it should return its content with the content-type application/javascript
.
So the simplest thing to do is put the path to a PHP (if that's what you're using) file and just ensure that what's returned is valid Javascript, sent with a correct Content-Type
HTTP header
Upvotes: 1
Reputation: 527043
Scripts specified via a src
attribute are handled just like any other resource on a page. If you return a 404
code, the browser won't bother trying to deal with the server further for that resource. The server gets all of the usual HTTP request information (assuming the browser sends it normally), and the Referrer:
header is set to the page which is including the resource.
Upvotes: 0