Skip to content

Commit 83311ff

Browse files
optimising the loading of scripts for websocket
1 parent 1e4705e commit 83311ff

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

my-client/src/components/EditorArea.vue

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,19 @@ export default defineComponent({
135135
const loadScript = (scriptPath) => {
136136
return new Promise(function (resolve, reject) {
137137
let tag = document.head.querySelector(`[src="${scriptPath}"`);
138-
tag = document.createElement("script");
139-
tag.src = scriptPath;
140-
document.head.appendChild(tag);
141-
tag.onload = () => {
138+
if (tag) {
142139
resolve(tag);
143-
};
144-
tag.onerror = () => {
145-
reject(new Error("Failed to load " + scriptPath));
146-
};
140+
} else {
141+
tag = document.createElement("script");
142+
tag.src = scriptPath;
143+
document.head.appendChild(tag);
144+
tag.onload = () => {
145+
resolve(tag);
146+
};
147+
tag.onerror = () => {
148+
reject(new Error("Failed to load " + scriptPath));
149+
};
150+
}
147151
});
148152
};
149153
const scriptsToLoad = [

0 commit comments

Comments
 (0)