# import-css

> Load CSS asynchronously without render blocking in the given order.

Latest version **3.0.0** (published 2017-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install import-css
pnpm add import-css
yarn add import-css
bun add import-css
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2017-11-18 |
| First published | 2017-02-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | dangreen |
| Maintainers | dangreen |
| Keywords | import-css, css |

## Links

- npm: https://www.npmjs.com/package/import-css
- Repository: https://github.com/TrigenSoftware/import-css
- Homepage: https://github.com/TrigenSoftware/import-css#readme
- Issues: https://github.com/TrigenSoftware/import-css/issues
- npm.io page: https://npm.io/package/import-css

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2017-11-18
- 2.0.0 — 2017-03-15
- 1.0.3 — 2017-02-18
- 1.0.2 — 2017-02-16
- 1.0.1 — 2017-02-14
- 1.0.0 — 2017-02-14

## README

# import-css

[![NPM version][npm]][npm-url]

[npm]: https://img.shields.io/npm/v/import-css.svg
[npm-url]: https://npmjs.com/package/import-css

Load CSS asynchronously without render blocking in the given order.

# Install

```bash
npm i -S import-css
# or
yarn add import-css
```

# About

`import-css` contains 2 variants of `importCSS` function

1. `link.js` variant uses `<link>` tag. If you want to import multiple styles for "progressive loading" recommended move all function calls before `</body>`.

2. `link-in-body.js` also uses`<link>` tag, but this variant a little lighter than `link.js` because of restricted to use only in `<body>`.

Also exist `*-async.js` variants of both files, where you can import CSS outside of queue.

# API

### importCSS(String url, String media)

Files: `link.js`, `link-in-body.js`

### importCSS(String url, String media, Boolean async)

Files: `link-async.js`, `link-in-body-async.js`

# Examples

critical css
```css
section, footer {
	display: none;
}
```

`section.css`
```css
section {
	display: block;
	color: green;
}
```

`footer.css`
```css
footer {
	display: block;
	color: red;
}
```

`index.html` with `link.js`
```html
<!DOCTYPE html>
<html>
	<head>
		<script>(link.js)</script>
		<style>(critical css)</style>
	</head>
	<body>
		<header>
			<h1>Header</h1>
		</header>
		<section>
			<h1>Section</h1>
		</section>
		<footer>
			<h1>Footer</h1>
		</footer>
		<script>importCSS('section.css')</script>
		<script>importCSS('footer.css')</script>
	</body>
</html>
```

---
[![NPM](https://nodei.co/npm/import-css.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/import-css/)

---
_Source: https://npm.io/package/import-css · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
