npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

append-files

v1.0.0

Published

Append CSS files in head and JS files in body tag.

Downloads

60

Readme

append-files

Append CSS files and inline CSS in head tag whereas JS files and embed JS in body tag.

Install

Via npm

npm install append-files

Via Yarn

yarn add append-files

Usage

If like to add the styles and script files only without defining any other attributes then you can do this:

Add Script Files:

import { appendScripts } from 'append-files';

var addScripts = [
  '/js/script.js',
  'http://example.com/test.js'
];

appendScripts(addScripts);

NOTE: In this way, you can only add the script files, not applicable for inline script. To add inline scripts or add attibutes on script tags, like id, async, nomodule etc pass them as an object as shown in the example below.

Add Script Files with its dependency:

If you need to append 2 or more script files and the second script is dependent on the first script then you can define add the dependent script like this:

import { appendScripts } from 'append-files';

var addScripts = [{
  'id': 'test-forms',
  'url': 'http://example.com/test.js',
  'dependentScripts': [{
    'url': '/js/script.js',
    'async': true,
  }]
}];

appendScripts(addScripts);

NOTE: In this case, id attribute MUST be defined otherwise, dependent scripts not appended as it is suppose to be.

Add Inline Script:

Pass the script to be added as inline:

import { appendScripts } from 'append-files';

var addScripts = [{
  'inline': 'alert(1);'
}];

appendScripts(addScripts);

Add Stylesheets:

import { appendStylesheets } from 'append-files';

var addStyles = [
  'http://example.com/test.css',
  '/css/style.css'
];

appendStylesheets(addStyles);

NOTE: In this way, you can only add the stylesheet files, not applicable for inline styles. To add inline styles, pass them as an object as shown in the example below.

Add Stylesheets and Inline Style:

This is the example by which you can add inline CSS and/or stylesheet files.

import { appendStylesheets } from 'append-files';

var addStyles = [
  {
    'href': 'http://example.com/test.css'
  },
  {
    'href': '/css/style.css'
  },
  {
    'inline': 'h1 { color: red; }'
  }
];

appendStylesheets(addStyles);

Supported Script Attributes

| Attributes | Type | Required | Description | | ----------- | ----- | ----------- | ------------- | | url | URL | Yes | URI of an script. Either url or inline is required. | | inline | String | Yes | script which is not loaded from the file, but embedded inside script tag. For example: alert(1);. Either url or inline is required. | | async | Boolean | No | Indicating that the browser should load the script asynchronously and then execute it as soon as it's downloaded. | | referrerPolicy | String | No | Indicates which referrer to send when fetching the script, or resources fetched by the script. | | id | String | No | unique id for an Script Tag. Required when using dependentScripts attribute. | | nomodule | Boolean | No | Indicate that the script should not be executed in browsers that support ES2015 modules. | | dependentScripts | Object | No | If you have 2 script Files and the first file has the dependency on the second file then you can use this attribute to define the dependent script.In this case, id attribute is required with the dependency. For further information, refer to the Add Script Files with its dependency: example. |

Supported Style Attributes

| Attributes | Type | Required | Description | | ----------- | ----- | ----------- | ------------- | | url | URL | Yes | URI of an stylesheet. Either url or inline is required. | | inline | String | Yes | style which is not loaded from the file, but embedded inside style tag. For example: h1 { color: red; }. Either url or inline is required. |

Tested

This package is tested with the React Application.