views:

41

answers:

2

I'm working on an API that sends HTML forms to external AJAX apps.

Would it be abusing the HTTP headers if I include information such as stylesheets and scripts to use in the headers? I'd like to keep the HTML as clean as possible.

+2  A: 

This feels like a bad idea.

Although you want to keep the HTML as clean as possible, the HTML block is the 'proper' place to put information on what stylesheets and scripts to include - as they have specific meanings to the HTML.

Putting it in the HTTP headers, although possible using custom header fields ("X-something-or-other"), obfuscates the way in which your app works making things more difficult for future developers to understand, and can inadvertently break should you need to change things later (such as your web server, HTTP client)...

CuriousPanda
Well, if he's just sending HTML fragments, the block is not the proper place to put it (unless he turns it into a proper HTML document, which seems overkill). A different exchange format (e.g. XML wrapping the HTML fragments and the stylesheet) is probably a cleaner way to do it. In theory there's nothing stopping him from adding extra headers, though.
Alan
+3  A: 

In my point of view: Yes it would.

You better have to keep your transmission protocol (HTTP which is precisely specified in some RFC) as clean as possible than the message transmitted (HTML).

If you are working on creating an API, maybe you should create specifics XML messages that would contain 3 encapsulating parts: one for your stylesheets, one for your scripts and one for your HTML.

That's just an idea, I don't know what your are doing exactly.

Kaltezar
I like the idea of encapsulating the different parts. My lazy brain didn't think farther than the headers as a means of transportation.
Jrgns