Does it send an HTTP GET request for the specified file? I’m trying to write my own NodeJS webserver, and want to know how to go about dealing with sending the browser the javascript files it needs.
Let’s say I’m using several javascript libraries for a web-app I’m building, and for each of them I have a script tag in the head of my HTML file (e.g. <script type="text/javascript" src="jquery.js"></script>). In my server, would I be able to code something up to call different functions based off of the src requested, and to return a file that isn’t necessarily in the same location that the HTML would make one expect it to be?
I’m still new to NodeJS and webservers in general, so I apologize if this is really obvious to other people out there…
Yes.
Then don’t worry about how the browser decides what HTTP requests to make. Just implement the HTTP specification.
This sounds like you are planning to serve up different content for the same URI based on the referer header … I’d expect this to hit a cache and turn into a race condition based nightmare. Don’t do it. Write your HTML so if you need different scripts, you request them from different URIs.
If, on the other hand, you mean that you want to return data without reading it out of a file on the file system, then that is fine. Clients don’t care how the server determined what data to put in an HTTP response. Just make sure that it is sane and consistent.