diff --git a/doku.php b/doku.php
index d02a4320019d492e5a319fa93f2bd35276bc47e1..0b486e9eda8aa78daf56f5178a1c8a01fb42e9a8 100644
--- a/doku.php
+++ b/doku.php
@@ -90,10 +90,6 @@ if($DATE_AT) {
 //make infos about the selected page available
 $INFO = pageinfo();
 
-//export minimal info to JS, plugins can add more
-$JSINFO['id']        = $ID;
-$JSINFO['namespace'] = (string) $INFO['namespace'];
-
 // handle debugging
 if($conf['allowdebug'] && $ACT == 'debug') {
     html_debug();
diff --git a/inc/template.php b/inc/template.php
index 7eef41aad8d99e410a3b8802d4960060a159214c..720513b0f4d4f57277f2caf04cce3022875291e0 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -330,9 +330,7 @@ function tpl_metaheaders($alt = true) {
     if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
         $script .= "var SIG='".toolbar_signature()."';";
     }
-    $JSINFO['ACT'] = act_clean($ACT);
-    $JSINFO['DOKU_UHN'] = (int) useHeading('navigation');
-    $JSINFO['DOKU_UHC'] = (int) useHeading('content');
+    _tpl_ensureJSINFO();
     $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
     $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
 
@@ -355,6 +353,20 @@ function tpl_metaheaders($alt = true) {
     return true;
 }
 
+function _tpl_ensureJSINFO() {
+    global $JSINFO, $ID, $INFO;
+
+    if (!is_array($JSINFO)) {
+        $JSINFO = [];
+    }
+    //export minimal info to JS, plugins can add more
+    $JSINFO['id']                    = $ID;
+    $JSINFO['namespace']             = (string) $INFO['namespace'];
+    $JSINFO['ACT']                   = act_clean($ACT);
+    $JSINFO['DOKU_UHN']              = (int) useHeading('navigation');
+    $JSINFO['DOKU_UHC']              = (int) useHeading('content');
+}
+
 /**
  * prints the array build by tpl_metaheaders
  *