Domino, documents and content-types

November 10, 2009 at 9:11 pm

After many years of developing in Notes and Domino, there are some standard design patterns I tend to use over and over. One of these is placing as much (or all) of my client-side code – including Javascript libraries and CSS style sheets – in data documents, rather than design elements. Treating this portion of your application as data has some downsides (think about template deployments) , but also has the advantage of allowing for easier code modification.

 

One drawback, however, is that you may want or need to control the content-type http header sent back from the server. One example is with CSS style sheets – W3C- compliant browsers will not respect styles in a CSS page which is returned as content-type text, or text/html – the page must return as “Content-type: text/css”. Now, IE6 will respect such CSS pages,but IE7 and Firefox will not.

 

As a side note, during development, I really prefer to use Firefox for testing my applications, given the rich debugging environment available. Even when deploying an application in an internal corporate environment, in which we can control the end users to always use a particular IE variant, I still use Firefox for development testing.

 

So, if you have a simple “CODE” form in Domino and each of your code libraries sits in a document using this form, by default Domino will serve these back as content-type: text/html. Not what you want. You cannot control the content-type header through fields on a form, or through the HTMLHead form attribute, or anything along those lines. (Don’t try to use @SetHTTPHeader for content-type in a WebQueryOpen agent – it will be ignored). But you really want something like
“text/javascript” or “text/css” to be set as the content-type header, depending on the type of code in this library document.  So, here is the basic approach I have been using:

 

  • Create a subform with the basic fields used for your resource files – such as title, code, etc. And also a radio button field for the Content Type (with values of Javascript, CSS, JSON, XML, etc). And a computed DocType field which computes to “RESOURCE”.
  • Create a distinct form for each resource type – for example, one form for CSS resources; one for JavaScript resources; etc. For each form, set the form’s content type as appropriate – for example, “text/javascript” or “application/json”.  Include nothing on each form other than the one subform.
  • Create a view with a selection formula which includes documents created with DocType of “RESOURCE”, and with a form formula which computes to the appropriate form based on the “Content Type” radio button.
That’s all – you can then reference any of the resource documents in a form or page’s HTMLHead formula, using a simple formula such as:

 

“/” + @webDbName + “/vwResource/myJavascript.js”

 

The resource will be served by Domino with the appropriate content-type header.
Advertisement

Entry filed under: domino. Tags: , .

Domino: Access control lists demystified CSS: IE6 compatibility for <a> tags with no href attribute


Ed Schembor’s Blog

Adventure's of an application developer, living in the world of corporate IT.

Feeds

Categories


Follow

Get every new post delivered to your Inbox.