Affects Version/s: 3.1, 3.2
Affected Branches:MOODLE_31_STABLE, MOODLE_32_STABLE
Fixed Branches:MOODLE_31_STABLE, MOODLE_32_STABLE
Pull from Repository:
Pull Master Branch:
Pull Master Diff URL:
The core/template and core/str AMD modules requires templates / strings to be preloaded if you intend to use them in loops.
If you don't preload the template or string you can end up with the same AJAX request fired over and over (which is bad for performance).
Steps to replicate:
1) Install the attached local plugin which demonstrates this issue 'local_templateissue.zip'
2) Open your development tools (Chrome or Firefox) and enable the networking tab
Observe the crazy number of network requests made to satisfy 1 template + string.
If you inspect the requests you can see that they are all for the template and the string - "core_output_load_template" and "core_get_string"
3) Reload the page
Observe that on the second page load this doesn't happen
4) Open a different browser or clear browser cache (not moodle cache) and repeat steps 2 + 3
Observe that the crazy number of network requests has happened again
This is a potential performance issue that affects users on their first page load - it can cause blocking so the page takes ages to load and appears unresponsive.
As first impressions are important, I'd say it's a significant problem.
Also, imagine how bad it is for the server to be receiving the same requests over and over again when a new cohort of students logs on for the first time using a browser that does not have anything cached!
Templates and strings can be preloaded to avoid this issue BUT it would be nice if the template and str AMD module was improved to automatically handle this:
Before workaround in non-core plugin code: