{"id":17128031,"url":"https://github.com/msmathers/laterscript","last_synced_at":"2025-03-24T04:18:49.748Z","repository":{"id":142565049,"uuid":"260470593","full_name":"msmathers/laterscript","owner":"msmathers","description":"Defer \u0026 programmatically trigger loading of \u003cscript\u003e tags.","archived":false,"fork":false,"pushed_at":"2020-05-05T21:29:13.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T10:19:11.048Z","etag":null,"topics":["defer-loading","load-js","script-tag"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msmathers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2020-05-01T13:51:26.000Z","updated_at":"2020-05-05T21:29:16.000Z","dependencies_parsed_at":"2023-04-10T17:49:01.935Z","dependency_job_id":null,"html_url":"https://github.com/msmathers/laterscript","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/msmathers%2Flaterscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msmathers%2Flaterscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msmathers%2Flaterscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msmathers%2Flaterscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msmathers","download_url":"https://codeload.github.com/msmathers/laterscript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245206834,"owners_count":20577583,"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":["defer-loading","load-js","script-tag"],"created_at":"2024-10-14T19:06:05.129Z","updated_at":"2025-03-24T04:18:49.729Z","avatar_url":"https://github.com/msmathers.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u0026lt;laterscript\u0026gt;\n\nDefer \u0026 programmatically trigger loading of `\u003cscript\u003e` tags.\n\nThis is useful for external, third party JS dependencies that you want to embed in a base HTML template but don't want to load \u0026 parse until a later, programmatically-invoked time.\n\n## Usage\n\nInclude the laterscript JS tag above your first `\u003claterscript\u003e` tag.\n```html\n\u003cscript type=\"text/javascript\" src=\"https://cdn.jsdelivr.net/gh/msmathers/laterscript@master/js/laterscript.js\"\u003e\u003c/script\u003e\n```\n\nUse a `\u003claterscript\u003e` tag for inline or remote JS scripts.  Make sure it has an ID.\n```html\n\u003claterscript id=\"myscript\" type=\"text/javascript\" src=\"/path/to/file.js\"\u003e\n\u003c/laterscript\u003e\n```\n\nActivate the script via `laterscript.load()`.  Returns a promise that resolves once the script has been loaded \u0026 parsed.\n```js\nlaterscript.load('myscript').then(function(scriptEl) {\n  console.log('script loaded!')\n})\n```\n\nThe `\u003claterscript\u003e` element is replaced with a `\u003cscript\u003e` element, which gets parsed and loaded once it hits the DOM.\n\n```html\n\u003cscript id=\"myscript\" type=\"text/javascript\" src=\"/path/to/file.js\"\u003e\n\u003c/script\u003e\n```\n\n## Example\n\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cscript type=\"text/javascript\" src=\"https://cdn.jsdelivr.net/gh/msmathers/laterscript@master/js/laterscript.js\"\u003e\u003c/script\u003e\n    \u003claterscript id=\"jqueryjs\" type=\"text/javascript\" src=\"https://code.jquery.com/jquery-3.5.0.min.js\"\u003e\u003c/laterscript\u003e\n    \u003claterscript id=\"usejquery\" type=\"text/javascript\"\u003e\n      $(document).ready(function() {\n        $('body').html('\u003ch1\u003ejQuery loaded!\u003c/h1\u003e')\n      })\n    \u003c/laterscript\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cbutton id=\"load-query-btn\"\u003eLoad jQuery\u003c/button\u003e\n  \u003c/body\u003e\n  \u003cscript type=\"text/javascript\"\u003e\n    (function() {\n      var btn = document.getElementById('load-query-btn');\n      btn.onclick = function() {\n        laterscript.load('jqueryjs')\n          .then(function() { laterscript.load('usejquery') })\n      }\n    })()\n  \u003c/script\u003e\n\u003c/html\u003e\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsmathers%2Flaterscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsmathers%2Flaterscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsmathers%2Flaterscript/lists"}