Fix document body check

It is possible that session.js library is run to early and body is not available yet. In such case we can append script to head.