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.

Eliom: FAQ

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 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 .js used file might be out of date because :

  • The server is serving an old version. (you might want to recompile and/or restart the server)
  • You browser retains an old version in its cache (try ctrl-shift-r).

However, there is a ticket to avoid 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 forbidden ( 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 optional 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

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.

Why isn't my server value up-to-date in the client side

Server values are automatically sent only with the HTML page, to avoid making many useless requests.

If you want to update a server value, you can use a server function

Or, if it is a regular flow, have a look at Client/server communication

What is the difference between Eliom_content.Html5.D and F

Module F generates standard OCaml values that are serialized to be sent to the client. If you use To_dom.of_element on such values, you will get new DOM elements (copies), even if the element was in the page.

To avoid this copy and use the element from the page itself, the D module generates a unique id for all your HTML values, and insert it as an attribute to the HTML tag. Thus, function To_dom.of_element will be able to return the actual DOM element present in the page, and not a copy. This is probably what you want if you use the % notation on a node, for example to bind JS action. But the counterpart is that it pollutes the HTML page with long ids.

By default, we suggest to use module D, as it will probably do what you expect, and will avoid mistakes. But to optimize the size of your pages, you may want to use module F for each element you don't manipulate on client side. But be careful: it may introduce errors difficult to fix if you don't have this in mind constantly.

If your Web site is not using client side features at all, use F.

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 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 ...

Why my js code is not executed?

You probably forgot to include your js sheet in your pages.
Have a look to: How to add Javascript script sheet?

Why my js code is not executed if I don't use an application?

Applications include automatically your js script sheet. So you have to include it by yourself.
Have a look to: How to add Javascript sheet script?

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:

With old versions of tyxml:

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

Lwt: FAQ

Error : Unbound value >>=

The operator >>= is an infix function defined in module Lwt. Open module Lwt or redefine it:

let (>>=) = Lwt.bind