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

Method preconnect

src/custom-element.js:907–922  ·  view source on GitHub ↗

* Called to instruct the element to preconnect to hosts it uses during * layout. * @param {boolean} onLayout Whether this was called after a layout. * TODO(#31915): remove once R1 migration is complete.

(onLayout)

Source from the content-addressed store, hash-verified

905 * TODO(#31915): remove once R1 migration is complete.
906 */
907 preconnect(onLayout) {
908 devAssert(this.isUpgraded());
909 if (onLayout) {
910 this.impl_.preconnectCallback(onLayout);
911 } else {
912 // If we do early preconnects we delay them a bit. This is kind of
913 // an unfortunate trade off, but it seems faster, because the DOM
914 // operations themselves are not free and might delay
915 startupChunk(this.getAmpDoc(), () => {
916 if (!this.ownerDocument || !this.ownerDocument.defaultView) {
917 return;
918 }
919 this.impl_.preconnectCallback(onLayout);
920 });
921 }
922 }
923
924 /**
925 * See `BaseElement.R1()`.

Callers 2

buildInternalMethod · 0.95
layoutCallbackMethod · 0.95

Calls 5

isUpgradedMethod · 0.95
getAmpDocMethod · 0.95
devAssertFunction · 0.90
startupChunkFunction · 0.90
preconnectCallbackMethod · 0.45

Tested by

no test coverage detected