Ok, I found the problem. It’s from the MODx API. This is not a real solution to fix the API, but at least I know how to generate the same problem.
Check this code (this is the fixed version, with some problem as well.
<?php
01 # Registers Client-side CSS scripts - these scripts are loaded at inside the <head> tag
02 function regClientCSS($src){
03 if ($this->loadedjscripts[$src]) return '';
04 $this->loadedjscripts[$src] = true;
05 if (strpos(strtolower($src),"<style")!==false||strpos(strtolower($src),"<link")!==false) {
06 $this->sjscripts[count($this->sjscripts)] = $src;
07 }
08 else {
09 $this->sjscripts[count($this->sjscripts)] = "<style type='text/css'>@import:url($src)</style>";
10 }
11 }
12
13 # Registers Startup Client-side JavaScript - these scripts are loaded at inside the <head> tag
14 function regClientStartupScript($src, $plaintext=false){
15 if (!empty($src) && !array_key_exists($src, $this->loadedjscripts)) {
16 if ($this->loadedjscripts[$src])
17 return '';
18
19 $this->loadedjscripts[$src] = true;
20 if ($plaintext==true) $this->sjscripts[count($this->sjscripts)] = $src;
21 elseif (strpos(strtolower($src),"<script")!==false) $this->sjscripts[count($this->sjscripts)] = $src;
22 else $this->sjscripts[count($this->sjscripts)] = "<script type='text/javascript' language='JavaScript' src='$src'></script>";
23 }
24 }
25
26 # Registers Client-side JavaScript - these scripts are loaded at the end of the page
27 function regClientScript($src, $plaintext=false){
28 if ($this->loadedjscripts[$src]) return '';
29 $this->loadedjscripts[$src] = true;
30 if ($plaintext==true) $this->jscripts[count($this->jscripts)] = $src;
31 elseif (strpos(strtolower($src),"<script")!==false) $this->jscripts[count($this->jscripts)] = $src;
32 else $this->jscripts[count($this->jscripts)] = "<script type='text/javascript' language='JavaScript' src='$src'></script>";
33 }
?>
The fix that needs to be done:
1. Line 06: Change "$sjscripts" to "$this->sjscripts"
2. Line 15: Change "!empty($src) && array_key_exists($src, $this->loadedjscripts)" to "!empty($src) && !array_key_exists($src, $this->loadedjscripts)"
Now, with this fix, the problem still persist, the client side script won’t be attached to the output if you set the page uncached. So you need to make the page cached. After setting the page cached, the first time you access the page, it’s still gonna looks ugly, because this system won’t work when the page is still fetching from database. Now when you refresh the page, then the client scripts will be added. So for now, this is going to be a quick fix to the API. Maybe we need to fix this API, so that it will load the script, even the page is uncached/fetch from database.