This was orginally posted on FWG slack channel ref
I wrote orginally:
Hey folks: Recently I was thinking and also doing testings regarding how to improve the performance of the learning MFE and in particular regarding when a learner is: navigating between units in sequence.
The current flow of the MFE, is that it would load an iframe which its src would be an xblock component,
the iframe src would request to this ourseware-chromeless.html template/page from the platform.
So this means for every change UnitId, the MFE would change the iframe.src with a new src link corresponding to the unit the learner just navigated to
Assuming the following:
Fact: Typically the learner after finishing a unit would navigate to the next one
If we agree on fact, we can enhance the user/leaner experience by pre-rendering the next unitId, however since we are using iframe to render the unitId, then how’s responsibility is it pre-render the next unit?
While doing some quick testing it seems that pre rendering wont be useful if done by the parent document/MFE it would be helpful if 1) the pre-rendering is done by iframe and if 2) the navigating is done by iframe as well:The implementation would be first if MFE send/post message to the iframe to do pre-render e.g.
window.addEventListener("message",function(event){
if(event.data.type === 'prerender'){
let link = document.createElement("link")
link.setAttribute("rel","prerender")
link.setAttribute("href",event.data.nextUnitId)
document.body.appendChild(link)
}
}
And then when user wants to navigate to next unit we could send a postMessage again to ask the iframe to change location e.g.
window.addEventListener("message",function(event){
if(event.data.type === 'relocate'){
location.href = event.data.nextUnitId
}
}
However this would break some already existing code, because at this point iframe document.referrer
value is no longer the MFE (in particualr it would break the communication between the MFEs and iframe regading loading, scrolling…etc)
Anyway before investing more time into this I would like to your opinions on this, for example is there a way to enhance expirence without asking the iframe to pre-render , or is changing the location of the (iframe by the iframe) a security concern which has no way around.
Note: this implementation might be easier if imjplemented with legacy_learning because then both the iframe and the learning would share the same origin, but however I don’t think it worth implemeting that for the legacy course expeirnce since it will be fully deprecated soon I guess
@dave replied:
This kind of discussion may be better suited for the forums, but a few quick thoughts:
- I think the fundamental idea of making unit transition cheaper makes a lot of sense.
- Pre-rendering would have to be done in a way that doesn’t break researcher analytics assumptions.
- Understanding where the major bottlenecks would help us to better evaluate possible solutions.
For instance, if the server side of it is relatively quick for a Unit, but we’re wasting lots of time loading the DOM and re-fetching all the Mathjax resources and such, we might be able to use a library like Turbo to have the Unit iframe do a DOM-diff style of loading. I did a proof-of-concept with this a long time ago, and the main issue was that some XBlocks rely on pageLoad events to trigger initialization off of that wouldn’t properly fire in this case (ORA2 for example).