lazy loading amd works only if $CFG->cachejs = false;

lazy loading amd works only if $CFG->cachejs = false;

by niels seidel -
Number of replies: 3

I've developed an activity plugin that is setup with vue.js and webpack. During the development $CFG->cachejs in the config.php was set to false so that a file called app-lazy.js was delivered from the server (amd/src/) to the client. Everything works fine.

When I set $CFG->cachejs to true the file amd/build/app-lazy.min.js should be requested from the server. Note, amd/build/app-lazy.min.js and amd/src/app-lazy.js are identical files that were just copied by webpack.

However, the response to this request is an empty file: /moodle/lib/requirejs.php/1661439226/mod_longpage/longpage-lazy.js

As a consequence the plugin doesn't work. 

There is no error in the webserver log. The file size of app-lazy.js is 6MB. If I reduce the size to 2 MB nothing changes.

When I try to load and echo the content of app-lazy.js as text inside the view.php it is not fully displayed. Possibly, some characters infer that.

Moodle 3.11.7+ (Build: 20220527)'

Has anyone an idea what the problem could be?


Average of ratings: Useful (1)
In reply to niels seidel

Re: lazy loading amd works only if $CFG->cachejs = false;

by Евгений Мамаев -
Picture of Plugin developers
I have now the same problem with lazy loading amd modules. Is it really possible to do this in Moodle 3.11.x? Is it relevant for Moodle 4.0?
In reply to niels seidel

Re: lazy loading amd works only if $CFG->cachejs = false;

by Kaushal Saini -

As we are talking about Lazy Loading,

I found an amazing resource on Laravel Lazy Collections on internet and I thought it would be very helpful for all the developers so I like to share the it here.