#396 ✓resolved
Juho Vepsäläinen

Plugin "document.write" messes up RequireJS

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

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

    MadRabbit October 26th, 2010 @ 11:06 AM

    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.

  • Juho Vepsäläinen

    Juho Vepsäläinen October 26th, 2010 @ 11:40 AM

    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.

  • MadRabbit

    MadRabbit October 26th, 2010 @ 11:53 AM

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

  • Juho Vepsäläinen

    Juho Vepsäläinen October 26th, 2010 @ 12:23 PM

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

  • MadRabbit

    MadRabbit October 26th, 2010 @ 12:31 PM

    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

  • Juho Vepsäläinen
  • MadRabbit

    MadRabbit January 12th, 2011 @ 05:54 PM

    • 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

    MadRabbit January 12th, 2011 @ 06:01 PM

    • State changed from “new” to “resolved”
  • Juho Vepsäläinen

    Juho Vepsäläinen January 12th, 2011 @ 06:18 PM

    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

    MadRabbit January 12th, 2011 @ 06:35 PM

    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

    Juho Vepsäläinen January 16th, 2011 @ 03:31 PM

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

  • MadRabbit

    MadRabbit January 16th, 2011 @ 03:33 PM

    Sweet. Thanks for heads up!

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

RightJS Core Tickets

Shared Ticket Bins

People watching this ticket

Attachments

Pages