{"id":24030485,"url":"https://github.com/callmecavs/ajax-component","last_synced_at":"2025-04-19T11:41:34.569Z","repository":{"id":57175079,"uuid":"80683823","full_name":"callmecavs/ajax-component","owner":"callmecavs","description":"A Custom Element that AJAXs its content, style, and scripts.","archived":false,"fork":false,"pushed_at":"2017-02-03T19:17:17.000Z","size":436,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T07:22:44.526Z","etag":null,"topics":["ajax","custom-elements","web-components"],"latest_commit_sha":null,"homepage":"","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/callmecavs.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}},"created_at":"2017-02-02T01:48:10.000Z","updated_at":"2024-05-31T07:13:46.000Z","dependencies_parsed_at":"2022-09-03T08:52:03.121Z","dependency_job_id":null,"html_url":"https://github.com/callmecavs/ajax-component","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/callmecavs%2Fajax-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/callmecavs%2Fajax-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/callmecavs%2Fajax-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/callmecavs%2Fajax-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/callmecavs","download_url":"https://codeload.github.com/callmecavs/ajax-component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249685292,"owners_count":21310577,"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":["ajax","custom-elements","web-components"],"created_at":"2025-01-08T17:44:18.594Z","updated_at":"2025-04-19T11:41:34.534Z","avatar_url":"https://github.com/callmecavs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ajax-component\n\n[![ajax-component on NPM](https://img.shields.io/npm/v/ajax-component.svg?style=flat-square)](https://www.npmjs.com/package/ajax-component) [![Standard JavaScript Style](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)\n\nA [Custom Element](https://developers.google.com/web/fundamentals/getting-started/primers/customelements) that AJAXs its content, style, and scripts.\n\n\u003cimg src=\"https://github.com/callmecavs/ajax-component/blob/master/demo.gif\" width=\"480\"\u003e\n\n## Features\n\n* **HTTP2 first**. A component performs AJAX requests to fetch its HTML, CSS, and JS.\n* **Scoped CSS**. Via the Shadow DOM, `ajax-component` has native CSS scoping (no build step required).\n* **Scoped JavaScript**. Execute anything, with access to the global scope, but without polluting it.\n* **Familiar**. Same old HTML, CSS, and JS. Just new elements.\n\n## Install\n\n```sh\n$ npm i ajax-component --save\n```\n\n## Use\n\nDecide on a `name` for your element (it must contain a `-`).\n\n### HTML\n\nUsing your `name`, add the new element to your markup:\n\n```html\n\u003c!-- note that a closing tag is required --\u003e\n\u003cajax-component\u003e\u003c/ajax-component\u003e\n```\n\nThen, add the these attributes to load your resources:\n\n| Attribute | Extension | Required | Optional |\n| :-------- | :-------: | :------: | :------: |\n| `content` | .html     |          | ✓        |\n| `style`   | .css      |          | ✓        |\n| `script`  | .js       |          | ✓        |\n\n```html\n\u003c!-- will load HTML only --\u003e\n\u003c!-- while not technically required, scoped CSS and/or JS isn't useful without HTML --\u003e\n\u003cajax-component content=\"path/to/file.html\"\u003e\u003c/ajax-component\u003e\n\n\u003c!-- will load HTML content, scoped CSS, and scoped JS --\u003e\n\u003cajax-component\n  content=\"path/to/file.html\"\n  style=\"path/to/file.css\"\n  script=\"path/to/file.js\"\u003e\n\u003c/ajax-component\u003e\n```\n\nFinally, add the `fetch` attribute to your element.\n\nIt must have an initial value of `false` (or this wouldn't be an AJAX component).\n\n```html\n\u003cajax-component\n  fetch=\"false\"\n  content=\"path/to/file.html\"\n  style=\"path/to/file.css\"\n  script=\"path/to/file.js\"\u003e\n\u003c/ajax-component\u003e\n```\n\n### JavaScript\n\nUsing your `name`, in your JavaScript, pass it to the import:\n\n```javascript\n// import the default export\n// this is a function that accepts an element name\nimport createAJAXComponent from 'ajax-component'\n\n// call the imported function\n// pass the element name as used in the HTML to create the Custom Element\ncreateAJAXComponent('ajax-component')\n```\n\nAn element will AJAX its resources when the `fetch` attribute changes to `true`.\n\n```javascript\n// selected the element we want to load\nconst customEl = document.querySelector('ajax-component')\n\n// set the fetch attribute to true\ncustomEl.setAttribute('fetch', 'true')\n```\n\n## Browser Support\n\n`pjax-component` makes use of the [Custom Elements v1 API](https://developers.google.com/web/fundamentals/getting-started/primers/customelements). As such, it runs natively in the following (see [caniuse](http://caniuse.com/#feat=custom-elementsv1)):\n\n* Chrome 54+\n* Safari 10.1+\n* Opera 42+\n\n## Roadmap\n\n- [ ] Explore polyfill options (potential impact on scoping)\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT). © 2017 Michael Cavalea\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcallmecavs%2Fajax-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcallmecavs%2Fajax-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcallmecavs%2Fajax-component/lists"}