From 8c90ed1c499d7b2371255599821ef42f0863458b Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Tue, 17 Oct 2023 11:45:32 +0000
Subject: [PATCH] optimize courseware loading by loading chunk and app in
 parallel, fixes #3364

Closes #3364

Merge request studip/studip!2286
---
 .../javascripts/bootstrap/courseware.js       | 81 ++++++++++---------
 1 file changed, 45 insertions(+), 36 deletions(-)

diff --git a/resources/assets/javascripts/bootstrap/courseware.js b/resources/assets/javascripts/bootstrap/courseware.js
index d50331f8ea5..9ceac8ff9fc 100644
--- a/resources/assets/javascripts/bootstrap/courseware.js
+++ b/resources/assets/javascripts/bootstrap/courseware.js
@@ -1,100 +1,109 @@
 STUDIP.domReady(() => {
     if (document.getElementById('courseware-shelf-app')) {
-        STUDIP.loadChunk('courseware').then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-shelf-app" */
                 '@/vue/courseware-shelf-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-shelf-app');
-            });
+            ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-shelf-app');
         });
     }
 
     if (document.getElementById('courseware-index-app')) {
-        STUDIP.loadChunk('courseware').then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-index-app" */
                 '@/vue/courseware-index-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-index-app');
-            });
+            ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-index-app');
         });
     }
 
     if (document.getElementById('courseware-activities-app')) {
-        STUDIP.loadChunk('courseware').then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-activities-app" */
                 '@/vue/courseware-activities-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-activities-app');
-            });
+                ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-activities-app');
         });
     }
 
     if (document.getElementById('courseware-tasks-app')) {
-        STUDIP.loadChunk('courseware').then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-tasks-app" */
                 '@/vue/courseware-tasks-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-tasks-app');
-            });
+            ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-tasks-app');
         });
     }
 
     if (document.getElementById('courseware-content-bookmark-app')) {
-        STUDIP.loadChunk('courseware').then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-content-bookmark-app" */
                 '@/vue/courseware-content-bookmark-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-content-bookmark-app');
-            });
+            ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-content-bookmark-app');
         });
     }
 
     if (document.getElementById('courseware-admin-app')) {
-        STUDIP.loadChunk('courseware').then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-content-bookmark-app" */
                 '@/vue/courseware-admin-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-admin-app');
-            });
+            ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-admin-app');
         });
     }
 
     if (document.getElementById('courseware-public-app')) {
-        STUDIP.loadChunk('courseware').then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-public-app" */
                 '@/vue/courseware-public-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-public-app');
-            });
+            ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-public-app');
         });
     }
 
     if (document.getElementById('courseware-content-releases-app')) {
-        STUDIP.loadChunk('courseware').then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-content-releases-app" */
                 '@/vue/courseware-content-releases-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-content-releases-app');
-            });
+            ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-content-releases-app');
         });
     }
 
     if (document.getElementById('courseware-comments-app')) {
-        STUDIP.Vue.load().then(({ createApp }) => {
+        Promise.all([
+            STUDIP.loadChunk('courseware'),
             import(
                 /* webpackChunkName: "courseware-comments-app" */
                 '@/vue/courseware-comments-app.js'
-            ).then(({ default: mountApp }) => {
-                return mountApp(STUDIP, createApp, '#courseware-comments-app');
-            });
+            ),
+        ]).then(([{ createApp }, { default: mountApp }]) => {
+            return mountApp(STUDIP, createApp, '#courseware-comments-app');
         });
     }
 });
-- 
GitLab