I am writing a Http server using C#. This is the reference I used to develop and the server is working fine.
I have a html page(say index.html) with some javascript files(say login.js, validate.js, etc.,) on it. While requesting index.html from browser using url (http://localhost:8080/index.html), the server has to serve the index.html page. Now, the browser automatically sends a GET request for login.js(http://localhost:8080/login.js) and validate.js(http://localhost:8080/validate.js).
Is there any standard mechanism that server can use to distinguish between the request made for html and js (except parsing the url and looking for html/js ?
Yes, the client will send Accept headers to the server.
The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of a request for an in-line image.
The client will send the URI, which is the exact location of the resource. In your case its obvious what type of resource is available at the URI, but this doesnt have to be the case, the URI is just a string of text.
Clients will send a number of headers with a request. One header they may send is an Accept header. This indicates to server what content type the client is prepared to accept as a response to the request. In the case of a stylesheet it will ask for text\css
, for javascript text\javascript
etc. etc.
Based on the content / tone of your question, i would suggest you probably want to read up on mimetypes and http headers. The W3C specifications are thorough, but a bit dense, there are better resources available if you just want to get your head around the basics. Ask google.