MCPcopy
hub / github.com/vercel/next.js / getAssetPrefix

Function getAssetPrefix

packages/next/src/client/asset-prefix.ts:3–22  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import { InvariantError } from '../shared/lib/invariant-error'
2
3export function getAssetPrefix() {
4 const currentScript = document.currentScript
5
6 if (!(currentScript instanceof HTMLScriptElement)) {
7 throw new InvariantError(
8 `Expected document.currentScript to be a <script> element. Received ${currentScript} instead.`
9 )
10 }
11
12 const { pathname } = new URL(currentScript.src)
13 const nextIndex = pathname.indexOf('/_next/')
14
15 if (nextIndex === -1) {
16 throw new InvariantError(
17 `Expected document.currentScript src to contain '/_next/'. Received ${currentScript.src} instead.`
18 )
19 }
20
21 return pathname.slice(0, nextIndex)
22}

Callers 1

appBootstrapFunction · 0.90

Calls 2

indexOfMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected