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

grunt-dentist

v0.4.1

Published

Wisdom extraction from script tags

Downloads

2

Readme

grunt-dentist

This plugin will remove inline Javascript and CSS from your HTML and dump them to a new file, to be incorporated into your build process.

It can erase any script tags pointed at local assets, and replace the lot with single script tag pointed at a minified file. Likewise, it can erase any style and local link rel='stylesheet' tags and replace them with a single link tag.

Additionally, it knows to avoid templates and anything else which may be inlined using script tags.

Getting Started

This plugin requires Grunt ~1.0.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-dentist --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-dentist');

The "dentist" task

Overview

In your project's Gruntfile, add a section named dentist to the data object passed into grunt.initConfig().

grunt.initConfig({
  dentist: {
    options: {
      include_js: "/app.min.js",
      include_css: "/app.css",
      clear_scripts: true,
      clear_stylesheets: true,
      clear_comments: true,
      strip_whitespace: true
    },
    dist: {
      src: 'docs/index.html',
      dest_js: 'prod/js/inline.js',
      dest_css: 'prod/css/inline.css',
      dest_html: 'prod/index.html',
    },
  },
});

Options

options.include_js

Type: String Default value: app.min.js

The dentist will insert a single script tag into your HTML, preferably above the closing </body> tag. Point this at your minified Javascript file. Note that this file is not created by the dentist; it is your job to make sure it exists after further concat/minify tasks.

If set to null, the tag is not included.

options.include_css

Type: String Default value: app.css

The dentist will insert a single link tag into your HTML, preferably above the closing </head> tag. Point this at your minified CSS. Likewise, the dentist does not necessarily create this file.

If set to null, the tag is not included.

options.clear_scripts

Type: Boolean Default value: true

The dentist will remove any local Javascript references it finds. Any script tag not pointed at an external file will be excised.

options.clear_stylesheets

Type: Boolean Default value: true

The dentist will remove any local stylesheet references it finds. Any link rel='stylesheet' tag not pointed at an external file will be excised.

options.clear_comments

Type: Boolean Default value: true

The dentist will remove any HTML comments it finds. Legacy IE "conditional" comments will be preserved, as will multiline comments.

options.strip_whitespace

Type: Boolean Default value: true

The dentist will elide any extraneous whitespace (horror vacui) in the output files.

options.js_insert_marker

Type: String Default value: "<!-- DENTIST JS -->"

Marker indicating where to insert the script tag. Use with options.include_js.

options.css_insert_marker

Type: String Default value: "<!-- DENTIST CSS -->"

Marker indicating where to insert the CSS link tag. Use with options.include_css.

Usage

The script takes one src HTML file as input, and outputs any inline JS to the file marked dest_js, inline CSS to dest_css, and the cleaned HTML to dest_html. If any of the destination files are unspecified, they are not processed. For instance this task extracts inlined scripts only but does not touch HTML or CSS:

grunt.initConfig({
  dentist: {
    extract: {
      files: {
        src: 'docs/index.html',
        dest_js: 'prod/js/app.init.js',
      }
    },
  },
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using the suppiled Gruntfile.

And don't forget to floss!

Release History

  • v0.4.1 - 1 June 2016 - options for js_insert_marker and css_insert_marker
  • v0.3.5 - 1 June 2016 - upgrade dependencies, use grunt 1.0.0
  • v0.3.4 - 23 February 2014 - preserve multiline comments
  • v0.3.2 - 30 January 2014 - added style tag support, clearing comments
  • v0.2.0 - 28 January 2014 - post-publish fixes
  • v0.1.0 - 28 January 2014 - first release.