Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

nuxt-lazytube

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuxt-lazytube

Nuxt.js 3 nuxt-lazytube

latest
Source
npmnpm
Version
0.2.2
Version published
Weekly downloads
300
-36.71%
Maintainers
1
Weekly downloads
 
Created
Source

Nuxt Lazytube

Support for Nuxt 3


Embed a YouTube or Vimeo player easily and lazy load the video to save resources and reduces initial load size. Useful when performance and page size is important or for sites with many embedded videos.

For a simple example page with 10 videos, nuxt-lazytube will reduce loadtime by 7x and memory usage by 2-3x.

npm version GitHub License npm downloads Nuxt nuxt-feather-icons Static Badge

Demo online

Table of Content

Features

  • reduces initial load size by ~1.1 MB per video
  • fully responsive and customizable through props
  • provides methods to control (play, stop, pause and reset) embedded videos
  • provide options to set up custom title and preview of embedded videos
  • platform supported: Youtube and Vimeo

Demo

view nuxt-lazytube

Setup

Installation

nuxt-lazytube for Nuxt3 applications.

$ npx nuxi@latest module add nuxt-lazytube

Config

nuxt.config.js

{
     modules: [
        'nuxt-lazytube',
    ]
},

Usage

<template>
    <!-- Youtube Embed -->
    <LazyYoutube src="https://www.youtube.com/watch?v=TcMBFSGVi1c"/>

    <!-- Vimeo Embed -->
    <LazyVimeo src="https://player.vimeo.com/video/64654583"/>
</template>

API

Props

NameTypeDefault ValueDescriptionRequired
srcString``To load the video and iframe, the link must be from YouTube or Vimeo. Any additional query parameters in the URL will be automatically included.true
aspectRatioString16:9Maintaining the aspect ratio of video, perfect for responsively handling video embeds based on the width of the parent, should be in *:* format. e.g, 1:1, 4:3, 16:9 and 21:9.false
maxWidthString560pxDefines maximum width of video container.false
showTitleBooleantrueDefines whether to show video title on top.false
autoplayBooleanfalseDefines whether to load the iframe as the page loads (not recommended)false
thumbnailQualityStringstandardDefines the quality of thumbnail, should be one of the following default, medium, high, standard or maxresfalse
iframeClassStringly-iframeDefines the class on iframe elementfalse
customTitleString``Defines the custom title of the videofalse
customThumbnailString``Defines the custom thumbnail image link of the videofalse
iframePolicyString``Define iframe in COEP environments ['anonymous' or 'credentialless'].false

Slots

This Component provides some slots. You can use the named slot to render custom play button and loader:

SlotDescription
buttonSlot gives an ability to provide custom play button
loaderSlot gives an ability to provide custom loader

Methods

These methods let you control the player using JavaScript, so you can perform the operations like play, stop, pause and reset.

The user's browser must support the HTML5 postMessage feature. Most modern browsers support postMessage.

NameTypeUsage
playVideofunctionthis.$refs["lazyVideo"]['playVideo']()
stopVideofunctionthis.$refs["lazyVideo"]['stopVideo']()
pauseVideofunctionthis.$refs["lazyVideo"]['pauseVideo']()
resetViewfunctionthis.$refs["lazyVideo"]['resetView']()

Note: Must Replace lazyVideo with your ref.

Example


<script setup>
    const lazyVideo = ref()

    const handleClick = (event) => {
        lazyVideo.value[event]()
    }
</script>

<template>
    <div>
        <LazyYoutube
                ref="lazyVideo"
                src="https://www.youtube.com/embed/KfYkzXTut1Y"
        />

        <button @click="handleClick('playVideo')">Play</button>
        <button @click="handleClick('stopVideo')"> Stop</button>
        <button @click="handleClick('pauseVideo')"> Pause</button>
        <button @click="handleClick('resetView')"> Reset</button>
    </div>
</template>

⚖️ License

Released under MIT by @4slan.

Keywords

youtube

FAQs

Package last updated on 07 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts