Magpie HTML - v0.1.3
    Preparing search index...

    Function extractAssets

    • Extract assets metadata from parsed HTML document.

      Parameters

      • doc: Document

        Parsed HTML document

      • OptionalbaseUrl: string | URL | null

        Optional base URL for resolving relative URLs

      Returns AssetsMetadata

      Assets metadata object with categorized URLs

      Extracts all external assets referenced in the document, organized by type. All URLs are normalized to absolute format based on the document's base URL.

      The extractor finds assets from:

      • Images: <img>, <picture>, srcset, OpenGraph meta tags
      • Stylesheets: <link rel="stylesheet">
      • Scripts: <script src>
      • Fonts: CSS @font-face and url() with font extensions
      • Media: <video>, <audio>, <source>, <track>
      • Manifests: <link rel="manifest">
      • Preloads: <link rel="preload"> and <link rel="prefetch">
      • Connection hints: <link rel="dns-prefetch"> and <link rel="preconnect">
      const doc = parseHTML(htmlString);
      const assets = extractAssets(doc, 'https://example.com');
      console.log(assets.images);
      console.log(assets.stylesheets);
      console.log(assets.scripts);