Content negotiation

Content-Negotiation is a mechanism defined in the HTTP specification that makes possible to serve different “versions” of a document (or more generally of a resource) at the same URL, so that user agents can choose which version fit their capacities the best. W3C

This site uses a script outside of the Wordpress structure and a plugin courtesy of m0n5t3r to handle the content negotiation and send different browsers different doctypes and content-type information.

I had a bit of trouble initially to get it to work though because I kept getting an XML Parsing Error: xml declaration not at start of external entity which is generally caused by blank spaces or extra line returns at the beginning or ends of scripts. But I couldn’t find any errant spaces in either my content negotiation script or in the plugin.

It turned out the spaces were coming from my Wordpress template files which by default look like this:

<?php
/*
Template Name: Pages
*/
?>

<?php get_header(); ?>

Notice the space between the ?> after the template name and the start of the call to the header? That was the cause of my problem. With that gone, it was smooth sailing and I was free to use my content negotitation script to not only switch doctypes, but send different CSS to different browsers and set session variables for the stylesheet switcher and accesskeys assignment.

Browse by tags:

Tags: , ,

Share this article:

  • del.icio.us
  • Digg
  • Ma.gnolia
  • Reddit
  • StumbleUpon
  • Design Float

Subscribe to this site for regular updates

One response to Content negotiation. Add your own.

Comments

  1. 1

    Good article. Whitespace can be a killer. Learned this myself recently while trying to debug a script.


Required indicates required field.
Email will not be published

You can use these tags in your reply:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Leave a Reply

Contact details