Rocket loader js friendly - #179
Conversation
Rocket loader [1] is a general purpose asynchronous Javascript loader that is used by Cloudflare to speed up the page load. Rocket loader will replace some of the native javascript functions with their own optimised functions and that cause issues with divolte.js Issues caused by rocket loader: 1 - Access DOM array with [index] instead of item(index) In this case, the HTML DOM item function is not part of the Rocket Loader function wrappers, therefore we need to access the element with [index] instead of item(index) 2 - Rocket loader evaluates `document.currentScript` to null. This will fail in https://github.com/divolte/divolte-collector/blob/master/src/main/resources/divolte.js#L87-L108 , because `typeof null === object` [1] https://support.cloudflare.com/hc/en-us/articles/200168056-What-does-Rocket-Loader-do-
|
Not handling The DOM array situation is a little more complex: This notwithstanding, is there an easy way to automate testing of CloudFlare's Rocket loader? One final question: does everything work under CloudFlare if you add |
it works if I load the script this way <script data-cfasync='false' src='/divolte.js'></script>but it will not work when I load the script dynamically. var script = document.createElement('script');
script.async = 1;
script.src ='divolte.js';
script.setAttribute('data-cfasync', false);
document.body.appendChild(script);It seems CloudFlare ignores |
I haven't mentioned |
Rocket loader [1] is a general purpose asynchronous Javascript loader that is used by Cloudflare to speed up the page load. Rocket loader will replace some of the native javascript functions with their own optimised functions and that cause issues with divolte.js
Issues caused by rocket loader:
1 - Access DOM array with [index] instead of item(index)
In this case, the HTML DOM item function is not part of the Rocket Loader function wrappers, therefore we need to access the element with [index] instead of item(index)
2 - Rocket loader evaluates
document.currentScriptto null.This will fail in https://github.com/divolte/divolte-collector/blob/master/src/main/resources/divolte.js#L87-L108 , because
typeof null === object[1] https://support.cloudflare.com/hc/en-us/articles/200168056-What-does-Rocket-Loader-do-
please advise