{"id":15631299,"url":"https://github.com/tvler/lazy-progressive-enhancement","last_synced_at":"2025-04-13T21:11:34.844Z","repository":{"id":80799048,"uuid":"55871730","full_name":"tvler/lazy-progressive-enhancement","owner":"tvler","description":"A lazy image loader designed to enforce progressive enhancement and valid HTML.","archived":false,"fork":false,"pushed_at":"2020-05-29T22:32:50.000Z","size":16411,"stargazers_count":191,"open_issues_count":4,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T11:38:05.437Z","etag":null,"topics":["lazyload","progressive-enhancement"],"latest_commit_sha":null,"homepage":"http://tylerdeitz.co/lazy-progressive-enhancement/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tvler.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-04-09T23:29:16.000Z","updated_at":"2024-11-29T13:41:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"5e7554ef-0b45-4231-bcf4-d7644d7813be","html_url":"https://github.com/tvler/lazy-progressive-enhancement","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tvler%2Flazy-progressive-enhancement","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tvler%2Flazy-progressive-enhancement/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tvler%2Flazy-progressive-enhancement/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tvler%2Flazy-progressive-enhancement/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tvler","download_url":"https://codeload.github.com/tvler/lazy-progressive-enhancement/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782260,"owners_count":21160717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lazyload","progressive-enhancement"],"created_at":"2024-10-03T10:39:53.138Z","updated_at":"2025-04-13T21:11:34.817Z","avatar_url":"https://github.com/tvler.png","language":"JavaScript","funding_links":[],"categories":["Examples"],"sub_categories":["Images"],"readme":"# Lazy Progressive Enhancement\n\n### [Download, copy-paste, whatever ;)](lazy-progressive-enhancement.min.js)\n\n**[View website](http://tylerdeitz.co/lazy-progressive-enhancement/)**\n\nA lazy image loader designed to enforce progressive enhancement and valid HTML.\n\nNot a framework, not a library, just a function (with clean af markup).\n\n``` html\n\u003cnoscript\u003e\u003cimg …\u003e\u003c/noscript\u003e\n```\n\n``` js\nloadMedia(\n   element,\n   onload,\n   scroll\n)\n```\n**element:** *CSS String | NodeList | Element (optional)* – loads all images if not set\n\n**onload:** *Function (optional)*\n\n**scroll:** *Boolean (optional)* – loads image when visible\n\n### Benefits of Lazy Progressive Enhancement\n - Designed to enforce progressive enhancement and valid HTML.\n - Written in pure JS -- no dependencies.\n - Not a framework, not a library, just a function.\n - Works with responsive `srcset` images.\n - Works with iframes.\n\nOther lazy loaders promote [invalid HTML](https://www.w3.org/TR/html5/embedded-content-0.html#attr-img-src) by omitting the src attribute, or aren't compatible for users without javascript.\n\n### Contents\n - [Basic Usage](#basic-usage)\n - [Load Specific Images](#load-specific-images)\n - [onload Function](#onload-function)\n - [Scroll-Based Loading](#scroll-based-loading)\n - [Build](#build)\n\n## Basic Usage\n\nBy default, the function targets every `noscript` element on the page.\n\nAny attributes the image has in noscript (`class` / `id` / `alt` / etc) are kept.\n\n`HTML`\n```html\n\u003cnoscript\u003e\u003cimg alt=\"hello!\" …\u003e\u003c/noscript\u003e\n```\n\n`JS`\n```js\nloadMedia()\n```\n\n`End result HTML`\n```html\n\u003cimg alt=\"hello!\" …\u003e\n```\n\n## Load Specific Images\n\nYou can specify what images to load by passing in either\n 1. A CSS selector string (use if calling the function before `DOMContentLoaded`)\n 2. A NodeList of `noscript`s (from something like `document.querySelectorAll`)\n 3. A singular `noscript` Element (from something like `document.querySelector`)\n\n`HTML`\n```html\n\u003cnoscript id=\"this-one\"\u003e\u003cimg …\u003e\u003c/noscript\u003e\n\u003cnoscript id=\"not-this-one\"\u003e\u003cimg …\u003e\u003c/noscript\u003e\n```\n\n`JS`\n```js\nloadMedia('#this-one')\n```\n\n`End result HTML`\n```html\n\u003cimg …\u003e\n\u003cnoscript id=\"not-this-one\"\u003e\u003cimg …\u003e\u003c/noscript\u003e\n```\n\n## onload Function\n\nYou can hook an onload function for every loaded image\n\n`JS`\n```js\nloadMedia(null, function() {\n   this.classList.add('loaded')\n})\n```\n\n`End result HTML`\n```html\n\u003cimg class=\"loaded\" …\u003e\n```\n\n## Scroll-Based Loading\n\nThere's a default function to load images when they're scrolled into view.\n\nThis is a general solution, creating your own scroll-based loading functionality may be more performant.\n\nWill be updated to use [intersection observers](https://github.com/WICG/IntersectionObserver) when it becomes standardized.\n\n`JS`\n``` js\nloadMedia(null, null, true)\n```\n\n## Build\n`uglifyjs lazy-progressive-enhancement.js -m --comments \u003e lazy-progressive-enhancement.min.js`\n\n## Thanks\n[@agarzola](https://github.com/agarzola), [@raglannyc](https://github.com/raglannyc)\n\n--\n[MIT License (MIT)](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftvler%2Flazy-progressive-enhancement","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftvler%2Flazy-progressive-enhancement","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftvler%2Flazy-progressive-enhancement/lists"}