Is something like this possible?
<script src="http://myserver.com/some.js" my-custom-header="foo"></script>
Update (a bit more detail):
I've been asked if there was a way to communicate some parameters to the server as part of the script request using headers instead of GET params. I said, "no," but thought I'd double check.
In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.
Custom Headers are for troubleshooting, informational purposes, and specific server-side logic. For example, to send a GET request with a custom header name, you can use the "X-Real-IP" header, which defines the client's IP address. For a load balancer service, "client" is the last remote host.
Short answer: no. By default a script tag will just retrieve the resource specified in the src
attribute.
However, if you use an AJAX request to retrieve the script (and add it later/execute it), you can use the setRequestHeader
function of the XMLHttpRequest
object (see http://www.developertutorials.com/learn-ajax/custom-http-headers-2643.php).
You could also use more complex methods, such as using mod_rewrite
to rewrite paths, and include the parameters in the url. The best solution depends on what you want to do, and how much control you have over the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With