{"id":25541026,"url":"https://github.com/vivekmunde/ember-m-css-loader","last_synced_at":"2025-07-15T10:44:42.144Z","repository":{"id":22929118,"uuid":"97705063","full_name":"vivekmunde/ember-m-css-loader","owner":"vivekmunde","description":"Lazy loading CSS using simple Ember Service","archived":false,"fork":false,"pushed_at":"2022-12-12T08:43:48.000Z","size":3562,"stargazers_count":6,"open_issues_count":19,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-15T23:55:32.924Z","etag":null,"topics":["css-lazy-load","css-load-on-demand","css-loader"],"latest_commit_sha":null,"homepage":null,"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/vivekmunde.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-19T10:41:35.000Z","updated_at":"2020-03-31T17:11:07.000Z","dependencies_parsed_at":"2023-01-13T22:28:02.974Z","dependency_job_id":null,"html_url":"https://github.com/vivekmunde/ember-m-css-loader","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/vivekmunde/ember-m-css-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivekmunde%2Fember-m-css-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivekmunde%2Fember-m-css-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivekmunde%2Fember-m-css-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivekmunde%2Fember-m-css-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vivekmunde","download_url":"https://codeload.github.com/vivekmunde/ember-m-css-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivekmunde%2Fember-m-css-loader/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265429310,"owners_count":23763725,"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":["css-lazy-load","css-load-on-demand","css-loader"],"created_at":"2025-02-20T06:28:52.212Z","updated_at":"2025-07-15T10:44:41.840Z","avatar_url":"https://github.com/vivekmunde.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"ember-m-css-loader\n==============================================================================\n\nThis [Ember.js](https://emberjs.com/) addon helps load the css file(s) on demand, i.e. lazy loading, inside the `\u003clink\u003e` tag in the `document` `\u003chead\u003e` using the service `m-css-loader` .\n\n### Compatibility\nEmber@^3.0.0\n\n### Lazy Loading of CSS\n\n[CSS are render blocking resources.](https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-blocking-css) The ambitious SPAs need more than one CSS resources (external libraries) and some of these CSS resources can be more functionality centric and may not be required to get loaded on the Home screen or may be required only for few of screens. \n\nSuppose a web app uses Maps Library (like [leaflet](https://leafletjs.com)) for displaying maps, which comes with its own CSS. The maps are displayed only on couple of routes other than home screen. So the home screen is not needed to load the CSS for maps. The maps CSS should be loaded when the routes displaying maps are requested. In this scenario, its always preferable to load the CSS dynamically.\n\n## `.load(attr)`\n\nThe method to load a CSS file on demand.\n\n`attr` is a JSON object which holds the attribute values for the `\u003clink\u003e` tag to load CSS. It should at least have `href` property set to the source of the CSS. \n\n\tmCssLoader: Ember.inject.service('m-css-loader'), \n\tbeforeModel() {\n        this.get('mCssLoader').load({\n                href: 'http://cdn-assets/maps.css',\n                integrity: 'sha384-shfssiufhnof7348f738f7bw8g+Pmsjshdinwe98',\n                crossorigin: 'anonymous'\n            });\n    }\n\n#### Promise Based Load\n\nThe service `m-css-loader` returns a promise. The service listens to the events `onload` and `onerror` on the `\u003clink\u003e` tag in which the CSS is loaded. It resolves the promise inside `onload` event and rejects it if `onerror` event is raised. \n\nUse of this promise is completely optional and upto the requirement of the app. If a route needs to wait until the CSS gets loaded then the service can be used inside the `beforeModel` hook.\n\t\n\tmCssLoader: Ember.inject.service('m-css-loader'), \n\tbeforeModel() {\n\t\treturn this.get('mCssLoader').load({\n\t\t\thref: '/assets/maps.css'\n\t\t});\n\t}\n\n#### Caching\n\nThe service `m-css-loader` caches the `href`s loaded to avoid injecting the same CSS more than once.\n\n#### CORS\n\nThe service inserts a `\u003clink\u003e` tag which as good as having it hardcoded at the time of html load. So no [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) issue.\n\nInstallation\n------------------------------------------------------------------------------\n\n```\nember install ember-m-css-loader\n```\n\n\nUsage\n------------------------------------------------------------------------------\n\n[Longer description of how to use the addon in apps.]\n\n\nContributing\n------------------------------------------------------------------------------\n\n### Installation\n\n* `git clone \u003crepository-url\u003e`\n* `cd ember-m-css-loader`\n* `npm install`\n\n### Linting\n\n* `npm run lint:js`\n* `npm run lint:js -- --fix`\n\n### Running tests\n\n* `ember test` – Runs the test suite on the current Ember version\n* `ember test --server` – Runs the test suite in \"watch mode\"\n* `npm test` – Runs `ember try:each` to test your addon against multiple Ember versions\n\n### Running the dummy application\n\n* `ember serve`\n* Visit the dummy application at [http://localhost:4200](http://localhost:4200).\n\nFor more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).\n\nLicense\n------------------------------------------------------------------------------\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivekmunde%2Fember-m-css-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvivekmunde%2Fember-m-css-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivekmunde%2Fember-m-css-loader/lists"}