Ace editor loading issues

Ace editor loading issues

von Richard Lobb -
Anzahl Antworten: 5

Loading of the Ace editor is becoming more and more problematic, and the Moodle JavaScript minifier (<moodlehome>/lib/classes/minify.php and support classes) is a large part of the problem. It uses regular expression matching with some huge patterns (e.g. 14,000 characters). It seems that unless globally disabled by use of the $CFG->jsrev parameter, the minimisation is applied to any javascript file you load, unless the minimised version is already in cache. The Ace editor is a very large JavaScript file and the minimiser churns away at it for 10 seconds or more. On some systems, e.g. the latest Bitnami Moodle containers, it takes so long that the browser times out, so you never get to load Ace. Turning off the minimiser altogether loads Ace in a couple of seconds.

I would like to be able to minify Ace myself and have Moodle just load that minified version. Does anyone (Tim?) know if there's a way to do that?

Als Antwort auf Richard Lobb

Re: Ace editor loading issues

von Tim Hunt -
It should be possible to get this handled by Moodle's JS minifier during development, not on the fly when the page is viewed.

However, they keep tweaking Moodle's JS handling, which is probably for good reasons, but means I have to keep re-learning it.

Not sure when I will get a chance to look into this. Could be worth posting in Moodle's General developer forum.
Als Antwort auf Richard Lobb

Re: Ace editor loading issues

von stefan weber -
Hi Richard,

not sure if it's related - ever since upgrading Moodle to 3.6.7+ the Ace editor won't load for us.

On a test server with the exact same Moodle and plugin versions it does load - I got the error there once, but it vanished after deleting caches, which does not work on the prod server :(

It looks like it can't load ace.js via javascript.php (from dev console):

  1. Request URL:
  2. Request Method:
    GET
  3. Status Code:
    500 Internal Server Error
If i try the request URL directly, it will also not load, while on my test server it loads and displays the javascript.

Any ideas on how to fix this?
Als Antwort auf stefan weber

Re: Ace editor loading issues

von stefan weber -

more info:

on my test server, when i delete caches, the first time ace editor will also not load, but I can see that a cached file of proper size (354000 bytes) is created in /documents/moodledata/localcache/js

on my prod server, this file never gets created, so I guess something goes wrong in the caching/minifaction process?

Als Antwort auf stefan weber

Re: Ace editor loading issues

von Richard Lobb -

Thanks for reporting this, This is almost certainly the same problem. The Moodle javascript compressor seems to struggle with the ace.js file.

The only case I've had where it failed altogether was with the docker bitnami/moodle image. Increasing the timeout from 30 seconds to several minutes didn't solve the problem. I was hoping it might just go away as Moodle JavaScript handling evolved but now that you're reporting a problem on a production system, I need to find a solution.

The version of Ace I distribute with CodeRunner is the minimised build (src-min from this github repo). I just did a test with bitnami/moodle and found that switching to the non-minimised version solves the problem! The compressor handles the non-minimised ace.js very quickly.

So assuming you have admin-level access to your server, could you try the following please and let me know if that solves your problem?

cd /var/www/html/moodle/question/type/coderunner
mv ace ace.bak
git clone https://github.com/ajaxorg/ace-builds.git
ln -s ace-builds/src ace

If so, it looks like I should switch to distributing the non-minimised build of Ace in the standard CodeRunner release.

Als Antwort auf Richard Lobb

Re: Ace editor loading issues

von stefan weber -
thanks richard! that indeed solved the problem, and it now loads really fast