bf4 / controljs

Automatically exported from code.google.com/p/controljs
Apache License 2.0
0 stars 0 forks source link

Do not override document.write #13

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please provide any additional information below.

I'm trying to migrate a large real-world (yes, with ads and Google Maps) 
website to ControlJS and I've found out that it overrides document.write 
unconditionally and assumes that all scripts on the page are type="text/cjs". 
Now, I don't believe that it's possible to write a custom, asynchronous, fully 
compliant document.write function, so I don't really see why ControlJS tries to 
do this. From my point of view, the main goal of ControlJS is to improve the 
loading experience of existing websites, which might be coded in a non-ideal 
way, with inline scripts and everything. Because, seriously, on a 
well-engineered website such a library wouldn't be useful. I did a quick patch 
in my copy of ControlJS to a) disable CJS.docwrite and b) to actually check the 
type value in CJS.findScripts. Works quite well so far - the old-school 
3rd-party scripts are loaded in a blocking way, and my scripts are loaded with 
CJS.

You might also consider adding a data-cjsasync="false" attribute. By 
introducing such an attribute, I guess it would be possible to process all 
scripts with CJS _and_ toggle CJS.docwrite on a script-by-script basis. For 
example, GMaps do use document.write, but in a CJS-compatible manner, whereas 
most ad networks have such perverted scripts that it won't be possible to write 
a reasonable custom document.write for them...

Original issue reported on code.google.com by LeonidKh...@gmail.com on 7 Jan 2011 at 5:09

GoogleCodeExporter commented 9 years ago
I whole heartedly agree. I am also converting a huge real world international 
news site with ControlJS and the blanket document.write override is killing me. 
I would much rather SHUT IT OFF and have the optimization ONLY on scripts I 
specify.

Leonid, I'm going to make the same alterations and would love to see that 
changes you made as a sanity check against what I'm doing.

If you read through the script, there are so many comments about things still 
"TODO" for document.write a data-cjsasync="false" would be a wonderful addition 
to the script and make it much more usable until the document.write replacement 
is more polished. 

Original comment by gst...@globalpost.com on 21 Sep 2011 at 12:29