Scripts

Instagram Embed

Instagram is a photo and video sharing social media platform.

Nuxt Scripts provides a <ScriptInstagramEmbed> component that fetches Instagram embed HTML server-side and proxies all assets through your server - no client-side API calls to Instagram.

Instagram Embed

View source

Nuxt Config Setup

To use the Instagram Embed component, enable it in your nuxt.config:

export default defineNuxtConfig({
  scripts: {
    registry: {
      instagramEmbed: true
    }
  }
})

ScriptInstagramEmbed()

The ScriptInstagramEmbed composable lets you have fine-grain control over when and how Instagram Embed is loaded on your site.

const { proxy } = ScriptInstagramEmbed()

// renders server-side Instagram embed

Please follow the Registry Scripts guide to learn more about advanced usage.

Example

Using Instagram Embed only in production while using the proxy to send events.

<script setup lang="ts">
const { proxy } = ScriptInstagramEmbed()

// noop in development, ssr
// just works in production, client
function handleAction() {
  // renders server-side Instagram embed
}
</script>

<template>
  <div>
    <button @click="handleAction">
      Send Event
    </button>
  </div>
</template>

This registers the required server API routes (/_scripts/embed/instagram, /_scripts/embed/instagram-image, and /_scripts/embed/instagram-asset) that handle fetching embed HTML and proxying images/assets.

<ScriptInstagramEmbed>

The <ScriptInstagramEmbed> component:

  • Fetches the official Instagram embed HTML server-side
  • Rewrites all image and asset URLs to proxy through your server
  • Removes Instagram's embed.js script (not needed)
  • Caches responses for 10 minutes

Demo

Slot Props

The default slot receives:

interface SlotProps {
  html: string // The processed embed HTML
  shortcode: string // The post shortcode (e.g., "C3Sk6d2MTjI")
  postUrl: string // The original post URL
}

Named Slots

SlotDescription
defaultMain content, receives { html, shortcode, postUrl }. By default renders the HTML.
loadingShown while fetching embed HTML
errorShown if embed fetch fails, receives { error }

Supported URL Formats

  • Posts: https://www.instagram.com/p/ABC123/
  • Reels: https://www.instagram.com/reel/ABC123/
  • TV: https://www.instagram.com/tv/ABC123/

How It Works

  1. Server-side fetch: Nuxt fetches the Instagram embed HTML from {postUrl}/embed/
  2. Asset proxying: All images from scontent.cdninstagram.com and assets from static.cdninstagram.com are rewritten to proxy through your server
  3. Script removal: Nuxt removes Instagram's embed.js (not needed for static rendering)
  4. Caching: Nuxt caches responses for 10 minutes at the server level

This approach is inspired by Cloudflare Zaraz's embed implementation.

Privacy Benefits

  • No third-party JavaScript loaded
  • No cookies set by Instagram/Meta
  • No direct browser-to-Instagram communication
  • User IP addresses not shared with Instagram
  • All content served from your domain

Limitations

  • Only supports single-image posts (galleries show first image only)
  • Videos display as static poster images
  • Some interactive features are not available (likes, comments)
postUrlstring required

The Instagram post URL to embed.

captionsboolean = true

Whether to include captions in the embed.

apiEndpointstring = '/_scripts/embed/instagram'

Custom API endpoint for fetching embed HTML.