Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/4sllan/nuxt-lazytube
Nuxt Lazytube support for Nuxt 3
https://github.com/4sllan/nuxt-lazytube
iframe lazyload modules nuxt3 nuxtjs vimeo vue vuejs youtube
Last synced: 3 months ago
JSON representation
Nuxt Lazytube support for Nuxt 3
- Host: GitHub
- URL: https://github.com/4sllan/nuxt-lazytube
- Owner: 4sllan
- License: mit
- Created: 2024-02-24T18:28:43.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-08-01T15:21:51.000Z (5 months ago)
- Last Synced: 2024-08-03T09:22:13.149Z (5 months ago)
- Topics: iframe, lazyload, modules, nuxt3, nuxtjs, vimeo, vue, vuejs, youtube
- Language: Vue
- Homepage:
- Size: 359 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
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][npm-v-src]][npm-v-href]
[![GitHub License][license]][license-href]
[![npm downloads][npm-d-src]][npm-d-href]
[![Nuxt nuxt-feather-icons][nuxt-src]][nuxt-href]
[![Static Badge][sponsor-src]][sponsor-href][Demo online](https://nuxt-lazytube.netlify.app/)
[//]: # (| [Tutorial](https://medium.com/geekculture/light-and-responsive-youtube-embeds-faster-vue-web-page-load-speeds-c8e477b93f0f))
---
#### Table of Content
- [Features](#features)
- [Demo](#demo)
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
* [Props](#props)
* [Slots](#slots)
* [Methods](#methods)
* [Example](#example)## 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](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/devbox/nuxt-lazytube-forked-9lsw5v?file=%2Fpages%2Findex.vue)
## Setup
## Installation
> nuxt-lazytube for Nuxt3 applications.
```sh
$ npx nuxi@latest module add nuxt-lazytube
```### Config
***nuxt.config.js***
``` js
{
modules: [
'nuxt-lazytube',
]
},```
## Usage
```javascript
```
## API
### Props
| Name | Type | Default Value | Description | Required |
|--------------------|-----------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
| `src` | `String` | `` | To load video and iframe, should be Youtube/Vimeo video link. | `true` |
| `aspectRatio` | `String` | `16:9` | Maintaining 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` |
| `maxWidth` | `String` | `560px` | Defines maximum width of video container. | `false` |
| `showTitle` | `Boolean` | `true` | Defines whether to show video title on top. | `false` |
| `autoplay` | `Boolean` | `false` | Defines whether to load the iframe as the page loads _(not recommended)_ | `false` |
| `thumbnailQuality` | `String` | `standard` | Defines the quality of thumbnail, should be one of the following `default`, `medium`, `high`, `standard` or `maxres` | `false` |
| `iframeClass` | `String` | `ly-iframe` | Defines the class on iframe element | `false` |
| `customTitle` | `String` | `` | Defines the custom title of the video | `false` |
| `customThumbnail` | `String` | `` | Defines the custom thumbnail image link of the video | `false` |
| `iframePolicy` | `String` | `` | 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:
| Slot | Description |
|--------|-----------------------------------------------------|
| button | Slot gives an ability to provide custom play button |
| loader | Slot 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.
| Name | Type | Usage |
|------------|------------|-------------------------------------------|
| playVideo | `function` | `this.$refs["lazyVideo"]['playVideo']()` |
| stopVideo | `function` | `this.$refs["lazyVideo"]['stopVideo']()` |
| pauseVideo | `function` | `this.$refs["lazyVideo"]['pauseVideo']()` |
| resetView | `function` | `this.$refs["lazyVideo"]['resetView']()` |_Note: Must Replace `lazyVideo` with your [ref](https://v3.vuejs.org/guide/component-template-refs.html)._
### Example
```html
const lazyVideo = ref()
const handleClick = (event) => {
lazyVideo.value[event]()
}
Play
Stop
Pause
Reset
```
## ⚖️ License
Released under [MIT](/LICENSE) by [@4slan](https://github.com/4sllan).
[npm-v-src]: https://img.shields.io/npm/v/nuxt-lazytube/latest.svg?style=flat-square&colorA=18181B&colorB=28CF8D
[npm-v-href]: https://www.npmjs.com/package/nuxt-lazytube
[license]: https://img.shields.io/github/license/4sllan/nuxt-lazytube?style=flat-square&colorA=18181B&colorB=28CF8D
[license-href]: https://github.com/4sllan/nuxt-lazytube
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
[nuxt-href]: https://nuxt.com/
[npm-d-src]: https://img.shields.io/npm/dt/nuxt-lazytube.svg?style=flat-square&colorA=18181B&colorB=28CF8D
[npm-d-href]: https://www.npmjs.com/package/nuxt-lazytube
[sponsor-src]: https://img.shields.io/badge/-%E2%99%A5%20Sponsors-ec5cc6?style=flat-square
[sponsor-href]:https://github.com/sponsors/4sllan