Too many jQuery libraries are loading......

10
There is no way around it, all projects do contain a lot widgets. And many of those widgets have a jQuery Library in them. Within the current design, every widget includes their own version, and quite often not even minimized. Before a new users session can start, the browser needs to download all of them. With mobile and even sometimes on a desktop this takes longer that patience of its users. This not nice and unnecessary. The end user will blame Mendix, and Mendix will blame the developer.... We should re-thing the way of using jQuery! Does a widget need jQuery, for simile dom manipulations? Is there a way, we could share jQuery libs across widgets? Should widgets in the app store be minimized before approval? Can we change the most common widgets to use the same version of jQuery? Could the modeler and runtime be shipped with a jQuery library?
asked
6 answers
3

Hi Andries,

I'd like to chime in on Mendix's behalf, as you raise a few very good points that a lot of people ask us about.

We understand the need for jQuery and that many people rely on it to build widgets. However, jQuery is particularly nasty because it doesn't really play well with others, they don't package it in such a way that you can easily depend/load it neatly. This makes it hard for us to offer a clean way of allowing multiple developers to depend on it and not create conflicts. The fact that jQuery plugins monkey-patch the jQuery singleton only exacerbates the problem. Another issue is different widgets expecting depending/expecting different jQuery versions (some want 1.8, others 2.x)

That being said, we are looking into this problem and will come up with a proper solution in time. We don't want to jump in and ductape quickfix this because we feel that this requires a solid solution that will fundamentally solve this issue for everyone.

In the meantime, I have some notes that may clarify things a bit and help you out. For starters, you mention that these jQuery libs aren't minified. That may be true for the widget 'source', but as soon as you create an MDA we do infact minify everything into a widgets.js. In fact, I'd dare to go so far was to say that this file is actually smaller than if you'd minify jQuery and widgets separately.

Secondly, I believe Jelte raises a good point in that many widgets can omit the use of jQuery and instead use dojo selectors instead. I think we as Mendix can help out here by being a little more strict and proactive when accepting new widgets in the appstore, by checking to see if and why jQuery is loaded.

As to Marcel's suggestion to include jQuery in Mendix: it's something we're considering, but are hesitant to do because of the above mentioned reasons: you don't want everyone to monkeypatch the same jQuery instance and you want to leave the option of which jQuery version to use up to the developer.

Lastly, I feel Nikel & yourself have come up with a good interim solution by not including it in the widget, instead providing it separately via a 'dummie-widget' who's sole purpose is to offer jQuery.

answered
2

Why are libraries added at widget level anyways?

Why can't we create widgets where we define the dependencies in the widget but add the javascript sources at a Mendix project level.

So that when the widgets are generated the javascript for each widget points to the same library files.

Also when a widget is loaded into a project it should allow you to include the required Javascript libraries.

answered
1

I'll refer to the answer I gave on Github.

We'll check what is in Dojo build and how that might be configured in a way that jQuery is loaded from another source. I'd recommend that the use of jQuery is as little as possible. Right now, when we do approvals on widgets, we check if jQuery is included and why. If it is purely used for DOM manipulation, we prefer it to be rewritten to the use of Dojo.

answered
0

Distributing a stable jQuery version with Mendix would be great. Maybe Mendix 7? To allow a widget, it would have to use the Mendix supplied jQuery library. I would be more than happy to change my widgets to work this way.

answered
0

Wouldn't the simplest solution be to not include the jQuery libraries in widgets at all, and make it the responsibility of the project to provide them if needed?

answered
0

On of our implementation uses the following solution:

  • Move all jqueries libs in one widget
  • Change all widgets to load its jquery form this one lib.

Efficient, but sub optimal, because; we needed change many widgets, and you can not update widgets form the app store without editing.

https://forum.mendix.com/questions/6867/Conflict%20with%20you%20JQuery%20Widgets%20and%20duplicated%20loading%20of%20jQuery%20Libraries

answered