Posts tagged mime types
That’s using your head…er()
0This is just a quick tip that I know has been demonstrated in other places, but it’s one that I have used frequently to provide an excellent solution to a variety of problems.
If you are using any kind of language on the back-end of your web application (PHP, Python, Ruby, Perl, etc) then you will eventually find yourself in the position of having to send different types of content. It may be XML, it may be a PDF file, it may be streaming video. Whenever you are in this situation, you need to change the Content-type that is sent back to the client. In PHP, you would do this with the header() function. In Python, it’s send_header() with the BasicHTTPServer. Ruby has various methods depending on whether or not it’s Rails or CGI, etc. Ultimately, your back-end code needs to designate to the client that something other than text/html is coming down the pipe.
The reason I think this is worth mentioning is because you can also designate a type that is just for JavaScript. This means that you can assemble your JavaScript dynamically on the server side, and have it get read by your browser just as if it was a .js file!
