Frequently Asked Questions

General

What does Ocsigen mean?

It means Objective Caml web SIte GENerator

Is it using Apache? Is it an Apache module?

No. We use our own server for now. There may be an implementation of Eliom with Apache in the future (?).

Is it possible to use Ocsigen and Apache on the same server?

Yes. Using a "reverse proxy". Ocsigen's web server and Apache both have a reverse proxy module to redirect some requests to another server.

Are you using templates in Eliom?

Eliom does not say anything about the way to create pages. The only thing it does it to make possible the static typing of pages through various modules. There is no template system by default in Ocsigen but it would not be very difficult to plug one in Eliom if you do not want static validation of xhtml. We are working on a high level template system allowing to write kind of templates, but without loosing static typing of pages and modularity.

How to use a database with Eliom?

Eliom does not say anything about the database. You can use any library you want, but we recommend our Macaque library or the monadic version of pgocaml, that can be use in cooperative way with Lwt.

Eliom: FAQ

How to attach OCaml values to the HTML nodes sent to the client?

Use module Eliom_content.​Html5.​Custom_data.

When should I use getElementById?

Most of the time, you don't need getElementById when you program with Eliom. Even if the element is generated on server side, you can refer it through its name. For example:

let d = div ... in
... {{ ... %d ... }}

But you may want to use getElementById to find a node in the page that has been generated long before, or example if the server asks the client to update the DOM node representing some data.

The client code is loaded, but I keep receiving the error "Closure not found" on the console

The used .js file might be out of date: Either because the server is serving an old version or because you browser retains an old version in its cache (try ctrl-shift-r). However, there is a ticket for avoiding this inconsistency

Error when trying to use document.write

Eliom is serving pages as "application/xhtml+xml" to browser supporting it. On some browser, usage of "document.write" is forbiden ( for good reasons ) when the page is served as XHTML. This problem can happen when using google libraries (maps, analytics, ... ). It is possible to force eliom to serve pages as "text/html" by using the content_type optionnal parameter of registering functions. for instance if your application functor is Appl then use:

Appl.register_service
 ~path:["path"]
 ~get_params:unit
 ~content_type:"text/html"
 generation_function

On firefox the error message in the console is:
Error: An attempt was made to use an object that is not, or is no longer, usable

How do I create a cryptographically safe identifier?

Ocsigen_lib.​make_cryptographic_safe_string

The client side part of my Eliom application does not start and the JS inspector complains about eliom_appl_sitedata not being defined

Check that your service is registered with Eliom_registration.​App, and not Eliom_registration.​Html5. All services belonging to the application must be registered with that module.

Errors in the browser

Cannot call XYZ before the document is initially loaded

Calling certain functions (e.g. those in Eliom_content.​Html5.​To_dom) depends on the fact that the DOM is loaded and in place.

If you are receiving this error you probably have called such a function during the initialization phase of the client module (i.e. as a top level expression).

To work around this problem, just wrap the call into Eliom_client.​onload.

Cannot call XYZ on an element with functional semantics

Certain functions (e.g. those in Eliom_content.​Html5.​Manip and Eliom_content.​Html5.​To_dom) are working only on HTML elements with DOM semantics. This error states that you have called such a method XYZ on an element with functional semantics, which is also printed.

To fix this problem just use the functions from Eliom_content.​Html5.​D for creating that HTML element.

Code generating the following client values is not linked on the client
Code containing the following injections is not linked on the client

You may get hints on those cryptic IDs when grepping for it in the server type files (type_mli), or even the dump (eliomc -c -dump/js_of_eliom -c -dump) of the source file.

unwrap_value: incorrect value

This indicates that Eliom_unwrap.​unwrap has been applied to a value which is not the result of Eliom_wrap.​wrap.

Compilation

Infered type client value not found (123567890).

You have to regenerate the file type_mli. This should be done by the build system, so you probably have to update the depend files.

Js_of_ocaml: FAQ

A few questions collected from IRC, forums, or mailing lists

Ask for more information if answers are not detailed enough

What does Js_of_ocaml do to prevent memory leaks? IRC 2012/07/18

Internet Explorer used to leak memory: circular references between DOM elements and Javascript objects were not collected. This is fixed since IE8.

Is it possible to use two js_of_ocaml programs on the same page? IRC 2012/07/18

Yes, but with the current implementation you will probably need to wrap the generated Javascript code in a closure (function(){...generated.code...}()); We should eventually fix the compiler to do that automatically, but I need to double-check that this does not break anything before that ...

How to call an OCaml function from JS code?

Have a look at function Js.wrap_callback

TyXML: FAQ

Some HTML5 element or attribute is missing. What can I do?

The HTML standard is evolving continually and new tags and attributes are introduced regularly. If you find a missing tag or attribute:

let u = F.tot (Xml.node "u" (F.toeltl l)) (* For a new element compatible with Html5.F *)

Html5.F.to_attrib (Xml.string_attrib "role" "unescaped_content") (* for a new attribute *)

There is also Xml.​float_attrib, Xml.​int_attrib, etc.

Server: FAQ