Server IP : 104.21.14.103 / Your IP : 18.219.198.150 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/thread-self/root/home/giankuin/thietke365.net/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/base/utils/ |
Upload File : |
interface PreloadScriptParams { handle: string; src: string; version?: string; } /** * Appends a `<link>` tag to the document head to preload a script based on the * src and handle parameters. */ const preloadScript = ( { handle, src, version, }: PreloadScriptParams ): void => { const srcParts = src.split( '?' ); if ( srcParts?.length > 1 ) { src = srcParts[ 0 ]; } const selector = `#${ handle }-js, #${ handle }-js-prefetch, script[src*="${ src }"]`; const handleScriptElements = document.querySelectorAll( selector ); if ( handleScriptElements.length === 0 ) { const prefetchLink = document.createElement( 'link' ); prefetchLink.href = version ? `${ src }?ver=${ version }` : src; prefetchLink.rel = 'preload'; prefetchLink.as = 'script'; prefetchLink.id = `${ handle }-js-prefetch`; document.head.appendChild( prefetchLink ); } }; export default preloadScript;