View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|Target Version||1.3.0-rc.1||Fixed in Version||1.3.0-rc.1|
|Summary||0020081: Moving JS to bottom is causing 'ReferenceError: jQuery is not defined' errors|
Implementation of 0013285 is causing a regression. The Snippets plugins , which atrol and I heavily use for user support, no longer works.
16:28:50.864 ReferenceError: jQuery is not defined plugin_file.php:19:154 16:28:50.865 ReferenceError: jQuery is not defined plugin_file.php:7:4 16:28:50.865 ReferenceError: jQuery is not defined plugin_file.php:5:0
|Steps To Reproduce|
|Tags||No tags attached.|
The problem lies with EVENT_LAYOUT_RESOURCES plugin event, which is triggered at the end of HTML head.
The plugin relies on jQuery, but its own scripts are loaded before the library, which causes the error.
Furthermore, the event reference is now in contradiction with what the core actually does:
EVENT_LAYOUT_RESOURCES is a valid event event and should be used by plugins to link CSS & JS files.
The problem here is that the plugin has a dependency on JQuery. The plugin made an assumption about the presence of JQuery and when it is going to be loaded in the page. That's is the problem.
There are few ways to fix this:
(1) Move base JS libraries to <head> - backward compatible
Thanks for looking into this.
Correct. In 1.2, jQuery was a plugin of its own, so dependency was easily managed by making sure the jQuery plugin was loaded first.
Again, correct. With 1.3, since jQuery is part of core, plugins should be safe to assume that the library is loaded for them when the documentation tells them they can load their resources.
Keep in mind that plugins do not have so many options to load resources since they must rely on available events as provided by Core. As per documentation, EVENT_LAYOUT_RESOURCES was the right way to do things, until 0013285.
For the record, I am not saying that moving JS to the bottom was bad or wrong, or that the plugin should not adapt to the new method.
Now with regards to your proposed options:
IMO, this option implies fully reverting 0013285. Doing things half-way (i.e. only moving jQuery back up) doesn't make sense, as sooner or later we'll face the same issue with another plugin which relies on jQueryUI.
This event currently is not placed in the right location: it is triggered before jQuery is loaded. This implies either
After that, all plugins relying on jQuery or jQueryUI need to be adapted to use the new event.
I assume you're basing your recommendation on this Yahoo developers article .
I'd like to challenge that, and point out another argument which goes the other way, i.e. it's better to have a page that appears to load slightly more slowly, than a page that appears broken .
Based on the above, my personal choice would be option 1, i.e. move jQuery/jQueryUI back to the top.
Indeed... I only just found it while researching a bit on this so-called "best practice", sorry ;)
I would therefore like us to complete the discussion here before changing plugins, as I'd rather avoid having to revert them after reverting 0013285 if it comes to that.
@dregad - the excerpt below is from document 
I totally agree with the author assessment. For heavy JS app, most of the code will live in the JS thus there is no point in putting JS at the bottom. If you think about modern Backbone or Angular apps, there is really nothing in the page except that links to JS & CSS files.
Mantis is largely a content app. The JS is very lightly used (if any in most pages). So putting the JS at the bottom for MantisBT aligns well with the author argument (and possibly yours)
Good point @dregad. We should also based on this discussion update the documentation of the events in the developer manual to clarify our recommendation for plugin authors.
You're right of course, but we also have to consider where we'll be in a year or two.
With this additional issue, I think the best course of action at this time is to revert.
Just a thought from a humble developer, and I apologize if this has been mentioned before. It is good that jQuery is being included in the installation. However, jQuery constantly updates. Wouldn't it make more sense to keep it as a plugin, just like the Formatting or Graphs plugins? or even make it a core one? This would make it easier for developers to update the version if desired, without having to look in the mantis system directories.
+1 for reverting.
@bkraul, upgrading jquery whether it is in a plugin or not, is pretty much the same. It is currently a dependency for core and is treated in a consistent way with the rest of the libraries that we depend on.
I reverted the change.
For the record, this also impacted the source integration plugin's search page.
MantisBT: master 8d7ea37e
2015-09-11 10:03:14Details Diff
This change (see issue 0013282) introduced several regressions.
This reverts commit 2dbc86b10d10495f1312b781fe0a3519a0d7152a, reversing
changes made to aa9b4f8ad7908325633542840805c4c854adb1f1.
Fixes 0020081, 0020088
|mod - core/html_api.php||Diff File|
|2015-09-07 10:37||dregad||New Issue|
|2015-09-07 10:37||dregad||Status||new => assigned|
|2015-09-07 10:37||dregad||Assigned To||=> syncguru|
|2015-09-07 10:40||dregad||Relationship added||related to 0013285|
|2015-09-07 10:47||dregad||Note Added: 0051384|
|2015-09-07 11:05||dregad||Note Added: 0051386|
|2015-09-07 16:17||syncguru||Note Added: 0051390|
|2015-09-07 16:27||syncguru||Relationship added||related to 0020084|
|2015-09-07 17:56||dregad||Note Added: 0051391|
|2015-09-07 18:30||vboctor||Note Added: 0051394|
|2015-09-07 18:57||dregad||Note Added: 0051396|
|2015-09-07 19:06||syncguru||Note Added: 0051397|
|2015-09-07 20:17||vboctor||Note Added: 0051399|
|2015-09-08 04:29||dregad||Note Added: 0051401|
|2015-09-09 02:30||atrol||Relationship added||related to 0020088|
|2015-09-09 02:37||atrol||Note Added: 0051410|
|2015-09-09 02:45||dregad||Note Added: 0051411|
|2015-09-10 10:25||bkraul||Note Added: 0051437|
|2015-09-10 22:25||vboctor||Note Added: 0051444|
|2015-09-11 11:27||dregad||Changeset attached||=> MantisBT master 8d7ea37e|
|2015-09-11 11:27||dregad||Assigned To||syncguru => dregad|
|2015-09-11 11:27||dregad||Status||assigned => resolved|
|2015-09-11 11:27||dregad||Resolution||open => fixed|
|2015-09-11 11:27||dregad||Fixed in Version||=> 1.3.0-rc.1|
|2015-09-11 11:31||dregad||Note Added: 0051453|
|2015-12-06 02:45||vboctor||Status||resolved => closed|