• This repository has been archived on 07/Sep/2022
  • Stars
    star
    106
  • Rank 325,810 (Top 7 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Crisper

Split inline scripts from an HTML file for CSP compliance

Usage

Command line usage:

cat index.html | crisper -h build.html -j build.js
crisper --source index.html --html build.html --js build.js
crisper --html build.html --js build.js index.html

The output html file will load the output js file at the top of <head> with a <script defer> element.

Optional Flags:

  • --script-in-head=false
    • In the output HTML file, place the script at the end of <body>
    • Note: Only use this if you need document.write support.
  • --only-split
    • Do not write a <script> tag in the output HTML file.
  • --always-write-script
    • Always create a .js file, even without any <script> elements.
  • --csp-hashable-script-loader
    • Create a hashable script loader that supports hash-based CSP with strict-dynamic.
    • A strict CSP could look like this:
    script-src 'strict-dynamic' 'sha256-mUZwR5zj1qMvnzisSvfmC8JczLB0BUKW0Ohr3euDoIA=';
    object-src 'none';
    base-uri 'self';
    
  • -v | --version
    • Prints version number.

Library usage:

var output = crisper({
  source: 'source HTML string',
  jsFileName: 'output js file name.js',
  scriptInHead: true, //default true
  onlySplit: false, // default false
  alwaysWriteScript: false // default false
});
fs.writeFile(htmlOutputFileName, output.html, 'utf-8', ...);
fs.writeFile(jsOutputFileName, output.js, 'utf-8', ...);

Usage with Vulcanize

When using vulcanize, crisper can handle the html string output directly and write the CSP separated files on the command line

vulcanize index.html --inline-script | crisper --html build.html --js build.js

Or programmatically

vulcanize.process('index.html', function(err, cb) {
  if (err) {
    return cb(err);
  } else {
    var out = crisper({
      source: html,
      jsFileName: 'name of js file.js',
      scriptInHead: true, // default true
      onlySplit: false, // default false
      alwaysWriteScript: false //default false
    })
    cb(null, out.html, out.js);
  }
});

Breaking Changes from 1.x

  • Deprecated split API was removed
    • require('crisper').split()
  • Default value of script-in-head flag changed to true
    • This improves load performance by parallelizing HTML and script parsing
    • This will break document.write calls
    • If you experience problems, you can use --script-in-head=false argument or scriptInHead: false in library usage.

Build Tools

More Repositories

1

actor-boilerplate

A starting point for web apps based on the actor model.
TypeScript
424
star
2

wizzywid

What you see is what you deserve: a visual getting-started-tool for HTML, Custom Elements, and Polymer.
HTML
232
star
3

polydev

Automatic web components profiling in chrome devtools
HTML
123
star
4

lit-ssr

Experimental SSR for lit-html and LitElement
TypeScript
120
star
5

actor-helpers

TypeScript
108
star
6

todo-list

Polymer Summit Todo List App
HTML
96
star
7

uni-virtualizer

Monorepo for a "universal" (renderer-agnostic) virtual scroller and renderer-specific variants
TypeScript
95
star
8

zuperkulblog-progressive

A Progressive Web App built in Polymer
HTML
75
star
9

start-lit-element

Hello World app for LitElement.
JavaScript
68
star
10

arcs

Arcs
Kotlin
57
star
11

books

JavaScript
54
star
12

start-polymer3

A Hello World app for Polymer 3.0
JavaScript
52
star
13

html-modules-toolkit

Transforming HTML standards of the future into JavaScript standards of the past
TypeScript
47
star
14

indie-catalog

A simple catalog for demoing web components
HTML
44
star
15

lit-element-build-rollup

Build config for lit-element with Rollup and Babel
JavaScript
35
star
16

brick-viewer

A web component for viewing models built with a certain type of plastic brick!
TypeScript
35
star
17

async-demos

TypeScript
30
star
18

ristretto

An extensible test runner โ˜•๏ธ
TypeScript
30
star
19

polyicon

Polymer custom icon generator
HTML
30
star
20

shady-css-parser

A fast, small and flexible CSS parser.
TypeScript
28
star
21

cheese

HTML
27
star
22

polyperf

Simple webpage performance testing harness
HTML
26
star
23

split-element

Lazy loaded LitElements
TypeScript
24
star
24

template-instantiation

TypeScript
23
star
25

tedium

A bot for doing mass changes to github repos for the Polymer team
TypeScript
20
star
26

part-theme

Experimental proof of concept shim for ::part/::theme css.
JavaScript
19
star
27

lit-mail

TypeScript
18
star
28

polymer-2-carousel

Codelab
HTML
18
star
29

polymer-3-first-element

Create your first element with Polymer 3
JavaScript
16
star
30

amp-viewer

JavaScript
16
star
31

blocking-elements

Expose a stack of blocking elements https://github.com/whatwg/html/issues/897
JavaScript
15
star
32

iron-overlay

Overlay element that overcomes the stacking context trap
HTML
13
star
33

tsc-then

Like `tsc -w` but it runs a command of your choosing when compilation finishes
TypeScript
12
star
34

polymon

Seek out Polymer team members and capture them as Polymon! https://polymon.polymer-project.org
HTML
10
star
35

hot-elements

An interface for custom element classes to implement hot module reloading
9
star
36

project-health

TypeScript
9
star
37

perf-tester

An element to help performance test other elements.
JavaScript
8
star
38

PolymerRenamer

The Polymer Renamer helps developers integrate the Google Closure compiler with their Polymer projects by forwarding renames performed by the compiler to HTML and JS files.
Java
8
star
39

x-slides

Experimental slide deck elements.
TypeScript
7
star
40

prpl-ce-firebase

PRPL with Firebase Codelab
JavaScript
6
star
41

lit-html-build

Example Rollup build for lit-html
JavaScript
6
star
42

generator-polymer-init-vanilla-web-component

A Yeoman generator that scaffolds a vanilla web component template
HTML
6
star
43

css-slam

Minimal CSS, fast
TypeScript
6
star
44

template-instantiation-experiments

TypeScript
5
star
45

release-image

Generate Tweetable images from changelogs
TypeScript
5
star
46

lazy-lit-element

Non-blocking rendering for LitELement & UpdatingElement
5
star
47

lit-ssr-workspace

A workspace for working on lit-ssr and related projects
5
star
48

vexflow-elements

Web components for the VexFlow music notation renderer
JavaScript
5
star
49

news-docs

Polymer News documentation
HTML
5
star
50

empathy

Installing NPM modules for your front-end project? Pathify them with Empathy.
5
star
51

webmat

Web + format = webmat
TypeScript
4
star
52

angular-element

Experiment: Web Components with Angular Ivy templates
TypeScript
4
star
53

lit-plugin-docs

CSS
4
star
54

cancel-token

Implementation of https://github.com/littledan/proposal-cancelable-promises
TypeScript
4
star
55

arcs-cdn

Repository to serve as cloud provider (via gh-pages) for primary Arcs artifacts
JavaScript
3
star
56

grimlock

TypeScript
3
star
57

web-component-project-layouts

HTML
3
star
58

show-more

Element handling collapsible content with animation keyframes
HTML
3
star
59

simple-input

JavaScript
3
star
60

gen-closure-declarations

TypeScript
3
star
61

polymer-closure-sample

JavaScript
3
star
62

story-viewer

TypeScript
2
star
63

.allstar

2
star
64

koa-importmap

A Koa middleware module that can rewrite import specifiers for JavaScript modules based on the reference/presence of an importmap in the HTML document originating the request.
1
star
65

lit-samples

HTML
1
star
66

loose-it

Pre build Polymer bindings and property effects
TypeScript
1
star
67

kaon-experimental

Experiments in ES6 and Web Components
TypeScript
1
star
68

multitenant-prpl

prpl-server as a library test
HTML
1
star
69

story-viewer-starter

HTML
1
star
70

.github

1
star
71

async-dom

Async DOM APIs
HTML
1
star
72

template-benchmarks

A set of templating-related microbenchmarks
1
star
73

form-participation

Polyfill for the Form Participation API
TypeScript
1
star
74

polycasts

Source code for all your favorite polycasts!
HTML
1
star
75

awesome-sauce

A demo of an element with a documentation page.
JavaScript
1
star