Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Plugin "document.write" messes up RequireJS

#396

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?

Reported by Juho Vepsäläinen · October 24th, 2010 @ 01:32 PM

State: resolved
Milestone: none
Assigned to: nobody

Activity

  1. MadRabbit
    MadRabbit

    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 a document reference in any window. In fact a the place where you include your first script there is already HTML and HEAD tags exist.

    October 26th, 2010 @ 11:06 AM

  2. Juho Vepsäläinen
    Juho Vepsäläinen

    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.

    October 26th, 2010 @ 11:40 AM

  3. MadRabbit
    MadRabbit

    what do you mean by "theme system" ? do you mean skins?

    October 26th, 2010 @ 11:53 AM

  4. Juho Vepsäläinen
    Juho Vepsäläinen

    Yup. I think jQuery UI provides a nice example of this. See http://jqueryui.com/themeroller/ .

    October 26th, 2010 @ 12:23 PM

  5. MadRabbit
    MadRabbit

    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

    October 26th, 2010 @ 12:31 PM

  6. Juho Vepsäläinen
  7. MadRabbit
    MadRabbit
    • 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

    January 12th, 2011 @ 05:54 PM

  8. MadRabbit
    MadRabbit
    • State changed from new to resolved

    January 12th, 2011 @ 06:01 PM

  9. Juho Vepsäläinen
    Juho Vepsäläinen

    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.

    January 12th, 2011 @ 06:18 PM

  10. MadRabbit
    MadRabbit

    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

    January 12th, 2011 @ 06:35 PM

  11. Juho Vepsäläinen
    Juho Vepsäläinen

    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. :)

    January 16th, 2011 @ 03:31 PM

  12. MadRabbit
    MadRabbit

    Sweet. Thanks for heads up!

    January 16th, 2011 @ 03:33 PM

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.