Setting the Content-Type on a subversion file

By | August 19, 2006

If you want to link to an html file directly in a subversion repository, there is a problem. By default, subversion doesn’t distinguish between filetypes other than binary versus text. So when you request a (text) file directly from the repository, it comes in as text/plain, no matter what it really is. This causes all standards-following browsers to render it as text, which isn’t so good if it’s an HTML file. The same problem will also exist if you reference CSS files, as they will be ignored if they don’t have the correct MIME type (at least, this used to be the case with Firefox).

However, fixing this is pretty simple:

svn propset svn:mime-type text/html *.html
svn propset svn:mime-type text/css *.css

do a commit, and you can now provide links directly to HTML documents inside your repository.

This change can be made across all new files you put in the repository by adding the following lines towards the end of ~/.subversion/config:

*.html = svn:mime-type=text/html
*.css = svn:mime-type=text/css

This stuff is documented more in the subversion book. One word of warning, the MIME type for JavaScript files is application/x-javascript. If you set your .js files to this, then Subversion may start treating them as binary. I haven’t tested this, but it doesn’t matter, as Firefox doesn’t seem to care what the MIME type of JavaScript files is.

2 thoughts on “Setting the Content-Type on a subversion file

  1. sanj

    Thanks mate! This had me confused for quite a while.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.