MCPcopy Create free account
hub / github.com/ampproject/amphtml / installScript_

Method installScript_

examples/pwa/pwa.js:314–340  ·  view source on GitHub ↗

* @param {string} src * @param {string=} fallbackSrc * @param {string=} customElement * @param {string=} customTemplate

(src, fallbackSrc, customElement, customTemplate)

Source from the content-addressed store, hash-verified

312 * @param {string=} customTemplate
313 */
314 installScript_(src, fallbackSrc, customElement, customTemplate) {
315 const doc = this.win.document;
316 const el = doc.createElement('script');
317 el.setAttribute('src', src);
318 if (customElement) {
319 el.setAttribute('custom-element', customElement);
320 }
321 if (customTemplate) {
322 el.setAttribute('custom-template', customTemplate);
323 }
324 el.onload = () => {
325 log('- script added: ', src, el);
326 };
327 el.onerror = () => {
328 log('- script failed to load: ', src, el);
329 doc.head.removeChild(el);
330 if (fallbackSrc) {
331 this.installScript_(
332 fallbackSrc,
333 undefined,
334 customElement,
335 customTemplate
336 );
337 }
338 };
339 doc.head.appendChild(el);
340 }
341
342 /**
343 * @param {string} url

Callers 1

constructorMethod · 0.95

Calls 2

logFunction · 0.70
setAttributeMethod · 0.45

Tested by

no test coverage detected