Saturday, June 20, 2009

IE8 script cache and AJAX script replace

Today I tried debugging the MyFaces 2.0 AJAXS scripts in IE8. The debugger is quite nice. The hard side came in when I starting changing the scripts and tried testing my new script versions. IE8 prooved to be a resilient beast like it's anchestors and insisted on running an old script version. The nice button "clear browser cache" in the developer tools didn't do anything. What finally helped was the first menu option in menu "cache" - in german it says: Immer vom Server aktualisieren.
Now that I could step into my Javascript code things got even weirder. I had a simple

<span id="test"><script ... ></span>

construction and I tried do replace element "test" with an AJAX call. So what do you think happened? I did:

item.insertAdjacentHTML('beforeBegin', '<span id="test"><script ... ></span>');

and then checked item.previousSibling. I turned out IE8 had inserted:

<span id="test"></span>

It just left out my new script. I changed the HTML code to look like (don't ask me what gave me the idea to do so, years of suffering train intuition):

<span id="test">
<input type="hidden" />
<script ... >

and suddenly IE inserted it all like it should. If you want to know which tricks are necessary to trigger script execution have a look at the MyFaces repository:

It's interesting code - external and embedded scripts need to be treated differently.

No comments:

Post a Comment