Skip to main content
Scripts

Gravatar provides globally recognized avatars linked to email addresses. Its avatar API uses a SHA-256 hash of the normalized email address. Nuxt Scripts creates that hash on your server and proxies the image request.

Gravatar

View source

Nuxt Config Setup

Add this to your nuxt.config.ts to load Gravatar globally. Alternatively you can use the useScriptGravatar composable for more control.

export default defineNuxtConfig({
  scripts: {
    registry: {
      gravatar: {
        trigger: 'onNuxtReady',
      }
    }
  }
})

This config automatically enables first-party mode (bundle + proxy). See below to customise.

useScriptGravatar()

The useScriptGravatar composable lets you have fine-grain control over when and how Gravatar is loaded on your site.

const { proxy } = useScriptGravatar()

// renders Gravatar avatar via component

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

First-Party Mode: Privacy Focused Proxy

No extra config needed. The script is bundled from your domain (faster loads, no extra DNS lookup) and runtime requests are reverse-proxied through your server with automatic anonymisation (user IPs stay hidden from Gravatar, works with ad blockers). Learn more.

Mode
Bundle Proxy
Privacy
User IP addresses are anonymised. Other request data passes through.
export default defineNuxtConfig({
  scripts: {
    // ✅ First-party mode: bundled + proxied
    registry: {
      gravatar: {
        trigger: 'onNuxtReady',
      },
    },
  },
})

Example

Using Gravatar in a component with the proxy to send events .

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

// noop in development, ssr
// just works in production, client
function handleAction() {
  // renders Gravatar avatar via component
}
</script>

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

This script's proxy endpoints use HMAC URL signing when you configure a NUXT_SCRIPTS_PROXY_SECRET. See the security guide for setup instructions.

<ScriptGravatar>

The <ScriptGravatar> component renders a Gravatar avatar for a given email address. The avatar image request is proxied through your server, so Gravatar does not receive the user's IP address from that request.

Passing email puts the raw address in the same-origin image URL before the server hashes it. That URL can appear in browser, CDN, and server access logs. Pass a precomputed hash when the address should not enter those logs.

The integration also loads Gravatar's gprofiles.js directly for hovercard support, even when hovercards is false. The browser therefore still connects to Gravatar.

Demo

[email protected]

80×80px · Proxied through your server

Props

PropTypeDefaultDescription
emailstring-Email address, sent to your server proxy for hashing, not sent to Gravatar
hashstring-Precomputed SHA-256 hash of the email (alternative to email)
sizenumber80Avatar size in pixels
defaultstring'mp'Default avatar style when no Gravatar exists
ratingstring'g'Content rating filter
hovercardsbooleanfalseEnable hovercards on hover

useScriptGravatar()

The useScriptGravatar() composable builds proxied avatar URLs from an email address or hash.

export function useScriptGravatar<T extends GravatarApi>(_options?: GravatarInput) {}

See Registry Scripts for trigger and loading options.

cacheMaxAgenumber = 3600

Cache duration for proxied avatar images in seconds.

defaultstring = 'mp'

Default image to show when no Gravatar exists.

sizenumber = 80

Avatar size in pixels (1-2048).

ratingstring = 'g'

Content rating filter.

Example

Build an avatar URL after the Gravatar script loads:

<script setup lang="ts">
const { onLoaded } = useScriptGravatar()

const avatarUrl = ref('')

onLoaded((api) => {
  avatarUrl.value = api.getAvatarUrlFromEmail('[email protected]', { size: 120 })
})
</script>

<template>
  <img v-if="avatarUrl" :src="avatarUrl" alt="User avatar">
</template>