Plugin "document.write" messes up RequireJS
Reported by Juho Vepsäläinen | 2010-10-24 13:32:51 UTC
Various plugins contain "document.write" calls to define their CSS. This causes problem with RequireJS module loader. The problems stem from the fact that "document" hasn't been initialized while the RequireJS loads the modules.
Here's a quick example demonstrating the issue (http://gist.github.com/640561). Just add some suitable plugin "getModules".
It probably would make sense to get rid of the "document.write" calls altogether. Perhaps it's better to define the CSS explicitly instead?
Comments and changes to this ticket
-

MadRabbit 2010-10-26 11:06:52 UTC
Hey Juho,
I've never worked with requirejs need to check it out what's the problem. But I was wondering how is that possible that there is no
document? do they eval it on the server side or something? because there is always adocumentreference in any window. In fact a the place where you include your first script there is already HTML and HEAD tags exist. -

Juho Vepsäläinen 2010-10-26 11:40:54 UTC
I'm not familiar with the technical details. I know that it's definitely not a server side solution. There's more information at http://requirejs.org/docs/why.html . Hope that helps. :)
On longer term it might be interesting to migrate to use some form of theme system. I know there may be some overhead (unneeded CSS ie.) but it just could be worth it, particularly for those using multiple plugins.
-

-

Juho Vepsäläinen 2010-10-26 12:23:37 UTC
Yup. I think jQuery UI provides a nice example of this. See http://jqueryui.com/themeroller/ .
-

MadRabbit 2010-10-26 12:31:44 UTC
yes, we're kinda working on it. in rightjs ui 2 all the styles were cleaned up for that, plus there are couple of guys drawing things for skins. just with the release and stuff didn't have time to finish everything up
-

-

MadRabbit 2011-01-12 17:54:32 UTC
- Tag set to enhancement, ui
Hey Juho,
I've finally took care of the issue. I've cleaned up RightJS core itself from all the evals and document.writes and reworked the UI modules a bit differently, they still have the styles inlined but don't use document.write anymore.
I'm attaching all the fresh builds, please give them a spin when you'll have a moment.
-- and yeah, UI modules should be fine, but I'm not sure about RightJS core with a separated olds module, it uses some dark voodoo to determine the url from where to load the patch, so you might wanna check it out and use an all-in-one build or something.
LMK how it went
-

MadRabbit 2011-01-12 18:01:04 UTC
- State changed from new to resolved
-

Juho Vepsäläinen 2011-01-12 18:18:18 UTC
Thanks!
I'll try to give it a go soon and let you know how it works out. I think just getting rid of that "document.write" part helped a lot as that messed up the script loading before.
The author of RequireJS whipped together a module conversion script for jQuery UI btw. See https://github.com/jrburke/jqueryui-amd . I don't mind monkey-patching my RightJS code. Still something like that might make a good TODO later on. This is true especially if RequireJS and similar tools become more popular. I personally don't see why not considering having proper modules in JS is a huge boon for development.
-

MadRabbit 2011-01-12 18:35:12 UTC
can't disagree on that. I'm actually thinking about having some sort of rjs based loader, just didn't get to it for real yet. will get to it a bit later
-

Juho Vepsäläinen 2011-01-16 15:31:25 UTC
Just gave your package a go. Once I finished up replacing the old code with your one it ran just fine. No loading errors whatsoever. :)
-

Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
RightJS Core Tickets