{"id":22790504,"url":"https://github.com/kermage/lazyscripts","last_synced_at":"2026-02-23T08:33:58.589Z","repository":{"id":223589985,"uuid":"759952243","full_name":"kermage/LazyScripts","owner":"kermage","description":"Delay script loading until user interaction or timeout","archived":false,"fork":false,"pushed_at":"2025-04-22T06:36:21.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-15T18:24:23.786Z","etag":null,"topics":["javascript-utility","lazy-loading","site-optimization"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/kermage.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-02-19T16:25:27.000Z","updated_at":"2025-04-25T18:17:38.000Z","dependencies_parsed_at":"2024-02-21T03:28:11.426Z","dependency_job_id":"c1780a22-49fd-444d-9e88-fc53f657c096","html_url":"https://github.com/kermage/LazyScripts","commit_stats":null,"previous_names":["kermage/lazyscripts"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/kermage/LazyScripts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kermage%2FLazyScripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kermage%2FLazyScripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kermage%2FLazyScripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kermage%2FLazyScripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kermage","download_url":"https://codeload.github.com/kermage/LazyScripts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kermage%2FLazyScripts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29740020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T07:44:07.782Z","status":"ssl_error","status_checked_at":"2026-02-23T07:44:07.432Z","response_time":90,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript-utility","lazy-loading","site-optimization"],"created_at":"2024-12-12T02:27:11.737Z","updated_at":"2026-02-23T08:33:58.563Z","avatar_url":"https://github.com/kermage.png","language":"TypeScript","readme":"# LazyScripts\n\n\u003e \"A lightweight JS utility that loads your scripts only after user interaction or after a specified time.\"\n\n## Usage\n\nAdd the main loader `\u003cscript\u003e` tag normally to your HTML:\n\n```html\n\u003cscript src=\"https://unpkg.com/lazyscripts.js\" data-timeout=\"3500\" data-lazyscripts\u003e\u003c/script\u003e\n```\n\n- `data-timeout=\"3500\"` — (optional) Force load all scripts after 3.5 seconds if no user interaction detected\n- `data-lazyscripts` — (optional) Script identifier for integrations like WordPress; [see example below](#wordpress)\n\nUpdate scripts to use `type=\"lazyscript\"` and specify the URL in `data-src`:\n\n```html\n\u003cscript type=\"lazyscript\" data-src=\"https://example.com/heavy.js\"\u003e\u003c/script\u003e\n```\n\nModule scripts are supported and can be specified with `data-type=\"module\"`:\n\n```html\n\u003cscript type=\"lazyscript\" data-src=\"https://example.com/app.js\" data-type=\"module\"\u003e\u003c/script\u003e\n```\n\nInline scripts and the loading strategies `async` \u0026 `defer` are supported as well:\n\n```html\n\u003cscript type=\"lazyscript\"\u003e\n  console.log(\"Inline script\", \"LOADED!\");\n\u003c/script\u003e\n\n\u003cscript type=\"lazyscript\" data-src=\"analytics.js\" async\u003e\u003c/script\u003e\n\u003cscript type=\"lazyscript\" data-src=\"vendor.js\" defer\u003e\u003c/script\u003e\n```\n\n## Example\n\nCheck the [`/tests`](/tests) folder for a working implementation.\n\n### WordPress\n\nAutomatically convert all scripts to lazy-loaded versions using the [`WP_HTML_Tag_Processor`](https://developer.wordpress.org/reference/classes/wp_html_tag_processor):\n\n```php\nadd_action(\n  'template_redirect',\n  function () {\n    ob_start(\n      function ( $buffer ) {\n        $html = new WP_HTML_Tag_Processor( $buffer );\n\n        while ( $html-\u003enext_tag( 'script' ) ) {\n          if ( null !== $html-\u003eget_attribute( 'data-lazyscripts' ) ) {\n            continue; // Skip the main loader\n          }\n\n          $src  = $html-\u003eget_attribute( 'src' );\n          $type = $html-\u003eget_attribute( 'type' );\n\n          if ( $src ) {\n            $html-\u003eset_attribute( 'data-src', $src );\n            $html-\u003eremove_attribute( 'src' );\n          }\n\n          if ( $type \u0026\u0026 ! in_array( $type, array( 'text/javascript', 'module' ), true ) ) {\n            // https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type\n            continue;\n          }\n\n          $html-\u003eset_attribute( 'data-type', $type );\n          $html-\u003eset_attribute( 'type', 'lazyscript' );\n        }\n\n        return $html-\u003eget_updated_html();\n      }\n    );\n  }\n);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkermage%2Flazyscripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkermage%2Flazyscripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkermage%2Flazyscripts/lists"}