# resource-manager-js

> Loads and caches all resources needed for a web app including css, templates, and scripts

Latest version **5.0.7** (published 2018-09-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install resource-manager-js
pnpm add resource-manager-js
yarn add resource-manager-js
bun add resource-manager-js
```

## 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 | 5.0.7 |
| Published | 2018-09-08 |
| First published | 2015-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.11.2 |
| Dependencies | 0 |
| Unpacked size | 42.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Mark Kennedy |
| Maintainers | mkay581 |
| Keywords | resources, resource-manager, css loader, js loader, script loader, html loader, file loader, css file, js file, caching |

## Links

- npm: https://www.npmjs.com/package/resource-manager-js
- Repository: https://github.com/mkay581/resource-manager-js
- Homepage: https://github.com/mkay581/resource-manager-js#readme
- Issues: https://github.com/mkay581/resource-manager-js/issues
- npm.io page: https://npm.io/package/resource-manager-js

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 5.0.7 (latest) — 2018-09-08
- 5.0.6 — 2018-09-08
- 5.0.5 — 2018-09-07
- 5.0.4 — 2018-09-07
- 5.0.3 — 2018-09-07
- 5.0.2 — 2018-09-07
- 5.0.1 — 2018-09-07
- 5.0.0 — 2018-09-07
- 4.0.1 — 2017-12-12
- 4.0.0 — 2017-12-12
- 3.1.1 — 2017-12-12
- 3.1.0 — 2017-12-12
- 3.0.1 — 2017-06-10
- 3.0.0 — 2017-06-10
- 2.7.0 — 2017-01-19
- … 27 more at https://npm.io/package/resource-manager-js/versions

## README

[![Build Status](https://travis-ci.org/mkay581/resource-manager-js.svg?branch=master)](https://travis-ci.org/mkay581/resource-manager-js)
[![npm version](https://badge.fury.io/js/resource-manager-js.svg)](https://badge.fury.io/js/resource-manager-js)

# Resource Manager

A library that imports, loads and caches CSS, JavaScript, and HTML template files (and their contents) on-the-fly in a browser.  
Useful for preloading files programmatically (in background), loading and unloading scripts inside
the `<head>` of an html page (avoiding duplicates), or cases when you may want to keep your css, js and templates 
in separate files and only want to import them into an HTML page at different times.

## Installation
 
```
npm i resource-manager-js --save-dev
```

You can also use the dist files in the browser.

```html
<script type="module" src="node_modules/resource-manager-js/dist/resource-manager.min.js"></script>
```


## Usage

### Load CSS files

```javascript
var cssPaths = ['path/to/css/file', 'path/to/another/css/file'];
ResourceManager.loadCss(cssPaths).then(function () {
    // css files have been loaded!
});
```

### Load JavaScript files

You can load script files dynamically by calling the `loadScript()` method. When called, the supplied script
will be loaded into the `<head>` of the DOM and run immediately.

```javascript
ResourceManager.loadScript('path/to/js').then(function () {
    // script has been loaded!
});
```

### Request data endpoints

The `fetchData()` method makes XHR/ajax requests easy.

```javascript
ResourceManager.fetchData('path/to/data', {cache: true}).then(function (response) {
    // response has been retrieved!
    // print out the response
    console.log(response);
});
```


### Load template files

Load HTML file contents into an already-existing DOM element by using the `loadTemplate()` method.


```javascript
ResourceManager.loadTemplate('path/to/html/file', document.body).then(function () {
    // html contents have been loaded into the body element
});
```

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