Socket
Socket
Sign inDemoInstall

postscribe

Package Overview
Dependencies
Maintainers
6
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postscribe - npm Package Compare versions

Comparing version 1.4.0 to 2.0.0

AUTHORS

19

bower.json
{
"name": "postscribe",
"description": "Asynchronously write javascript, even with document.write.",
"keywords": ["document.write", "tag writer", "asynchronous", "javascript", "after load"],
"version": "1.3.2",
"main": "./dist/postscribe.min.js",
"repository":{
"license": "MIT",
"homepage": "https://krux.github.io/postscribe/",
"keywords": [
"document.write",
"tag writer",
"asynchronous",
"javascript",
"after load"
],
"main": "src/main.js",
"moduleType": "es6",
"repository": {
"type": "git",
"url": "git://github.com/krux/postscribe.git"
},
"dependencies":{},
"homepage": "https://krux.github.io/postscribe/"
"dependencies": {}
}
{
"name": "postscribe",
"description": "Asynchronously write javascript, even with document.write.",
"version": "1.4.0",
"version": "2.0.0",
"homepage": "https://krux.github.io/postscribe",
"bugs": "https://github.com/krux/postscribe/issues",
"license": "MIT",
"repository": {
"type": "git",
"url": "git@github.com:krux/postscribe.git"
},
"keywords": [

@@ -14,3 +21,2 @@ "document.write",

"name": "Derek Brans",
"email": "dbrans@gmail.com",
"web": "http://github.com/dbrans"

@@ -21,8 +27,6 @@ },

"name": "Derek Brans",
"email": "dbrans@gmail.com",
"web": "http://github.com/dbrans"
"web": "https://github.com/dbrans"
},
{
"name": "Nick Sullivan",
"email": "nick@sullivanflock.com",
"web": "http://creationeer.me"

@@ -32,3 +36,7 @@ },

"name": "Joshua Newman",
"email": "joshua.newman@krux.com"
"web": "https://github.com/jnewman"
},
{
"name": "Seth Yates",
"web": "https://github.com/sethyates"
}

@@ -39,42 +47,99 @@ ],

"name": "Joshua Newman",
"email": "joshua.newman@krux.com"
"web": "https://github.com/jnewman"
}
],
"bugs": "https://github.com/krux/postscribe/issues",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/krux/postscribe/blob/master/LICENSE"
}
],
"repository": {
"type": "git",
"url": "git@github.com:krux/postscribe.git"
"main": "dist/postscribe.js",
"browser": "dist/postscribe.js",
"dependencies": {
"prescribe": "^1.0.0"
},
"dependencies": {},
"devDependencies": {
"grunt": "0.4",
"grunt-cli": "0.1.13",
"grunt-contrib-concat": "0.5.0",
"grunt-contrib-jshint": "0.10.0",
"grunt-contrib-qunit": "0.5.2",
"grunt-contrib-uglify": "0.2.7",
"grunt-contrib-watch": "0.5.3",
"jquery": "^1.11.1",
"lodash": "2.4.1",
"phantomjs": "1.9.11",
"qunit": "^0.7.5",
"testem": "0.6.22"
"babel-core": "6.7.4",
"babel-eslint": "6.0.2",
"babel-loader": "6.2.4",
"babel-plugin-transform-es3-member-expression-literals": "6.5.0",
"babel-plugin-transform-es3-property-literals": "6.5.0",
"babel-plugin-transform-object-assign": "6.5.0",
"babel-preset-es2015": "6.6.0",
"babel-preset-es2015-loose": "7.0.0",
"babel-register": "6.7.2",
"babelify": "7.2.0",
"cz-conventional-changelog": "1.1.5",
"del": "2.2.0",
"eslint": "2.7.0",
"expect.js": "0.3.1",
"gulp": "3.9.1",
"gulp-babel": "6.1.2",
"gulp-esdoc": "0.2.0",
"gulp-eslint": "2.0.0",
"gulp-filter": "4.0.0",
"gulp-git": "1.7.1",
"gulp-header": "1.7.1",
"gulp-jscs": "3.0.2",
"gulp-rename": "1.2.2",
"gulp-strip-debug": "1.1.0",
"gulp-uglify": "1.5.3",
"isparta": "4.0.0",
"isparta-loader": "2.0.0",
"jquery": "1.11.3",
"jscs": "2.11.0",
"json-loader": "0.5.4",
"karma": "0.13.22",
"karma-babel-preprocessor": "6.0.1",
"karma-chrome-launcher": "0.2.3",
"karma-coverage": "0.5.5",
"karma-coveralls": "1.1.2",
"karma-expect": "1.1.2",
"karma-firefox-launcher": "0.1.7",
"karma-mocha": "0.2.2",
"karma-mocha-reporter": "2.0.0",
"karma-phantomjs-launcher": "1.0.0",
"karma-safari-launcher": "0.1.1",
"karma-sauce-launcher": "0.3.1",
"karma-sinon": "1.0.4",
"karma-sourcemap-loader": "0.3.7",
"karma-webpack": "1.7.0",
"mocha": "2.4.5",
"phantomjs-prebuilt": "2.1.7",
"sinon": "1.17.3",
"watchify": "3.7.0",
"webpack": "1.12.14",
"webpack-dev-server": "1.14.1",
"webpack-stream": "3.1.0"
},
"homepage": "https://krux.github.io/postscribe",
"engines": {
"node": ">=0.10"
"config": {
"ports": {
"cdn": "8080"
},
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"main": "postscribe.js",
"filename": "postscribe.min.js",
"babel": {
"presets": [
"es2015-loose"
],
"plugins": [
"transform-es3-member-expression-literals",
"transform-es3-property-literals",
"transform-object-assign"
],
"comments": true,
"compact": false
},
"scripts": {
"lint": "grunt jshint",
"tdd": "grunt watch",
"test": "grunt"
"build": "gulp build",
"clean": "gulp clean",
"doc": "gulp doc",
"lint": "gulp lint",
"release": "gulp clean && gulp build && gulp release",
"start": "gulp serve",
"tdd": "gulp tdd",
"tdd:coverage": "gulp tdd:coverage",
"test": "gulp test",
"test:ci": "gulp test:ci",
"test:cross-browser": "gulp test:cross-browser",
"test:debug": "gulp test:debug",
"test:nocoverage": "gulp test:nocoverage"
}
}
# Overview
Remote scripts, especially ads, block the page from doing anything else while they load. They contribute a large % to load times which [affects your bottom line](http://devnet.kentico.com/Blogs/Thomas-Robbins/September-2012/How-loading-time-affects-your-bottom-line-Infograp.aspx). *Asynchronous* ads do not block the page and can be delivered after core content - [Async FTW](http://www.krux.com/pro/broadcasts/krux_blog/synchronous_vs_asynchronous_tags_whats_the_big_deal/).
[![Version](https://img.shields.io/npm/v/postscribe.svg)](http://npmjs.com/package/postscribe)
[![License](https://img.shields.io/npm/l/postscribe.svg)](http://npmjs.com/package/postscribe)
[![Build Status](https://travis-ci.org/krux/postscribe.svg?branch=master)](https://travis-ci.org/krux/postscribe)
[![Code Climate](https://img.shields.io/codeclimate/github/krux/postscribe.svg)](https://codeclimate.com/github/krux/postscribe)
[![Coverage](https://img.shields.io/coveralls/krux/postscribe.svg)](https://coveralls.io/github/krux/postscribe)
[![Dependencies](https://img.shields.io/david/dev/krux/postscribe.svg)](./package.json)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
Why is it so hard to deliver ads asynchronously? Because they may contain calls to `document.write`, which expects to be handled synchronously. **PostScribe lets you deliver a synchronous ad asynchronously without modifying the ad code**.
Remote scripts, especially ads, block the page from doing anything else while they load. They contribute a large % to load times which
[affects your bottom line](http://devnet.kentico.com/Blogs/Thomas-Robbins/September-2012/How-loading-time-affects-your-bottom-line-Infograp.aspx).
*Asynchronous* ads do not block the page and can be delivered after core
content - [Async FTW](http://www.krux.com/blog/krux-engineers/synchronous-versus-asynchronous-tags-whats-the-big-deal/).
Shameless Plug: Using this standalone library is a great start, but if you want to go further and have your tags centrally managed instead of having them hard-coded on the page, Check out [Krux's SuperTag](http://www.krux.com/pro/whatwedo/manage/supertag/), developed by the same authors as this library.
Why is it so hard to deliver ads asynchronously? Because they may contain calls to `document.write`, which expects to be handled synchronously.
**PostScribe lets you deliver a synchronous ad asynchronously without modifying the ad code**.
### Approach
Other tag writing libraries exist (see [alternatives](#alternatives)), but PostScribe is novel in it's use of what we call DOM Proxies, a way to ensure that the content is written as close to the way the browser would natively write the content with `document.write`/`innerHTML`. Read: it behaves just like the browser would, without convoluted parsing or hacks.
Other tag writing libraries exist (see [alternatives](#alternatives)), but PostScribe is novel in its use of what we call DOM Proxies, a way to
ensure that the content is written as close to the way the browser would natively write the content with `document.write`/`innerHTML`. Read: it
behaves just like the browser would, without convoluted parsing or hacks.
For more information:
* [Presentation at HTML5devconf](http://youtu.be/ClzeilKwX10) by the author, Derek Brans
* [Presentation at HTML5devconf](http://youtu.be/ClzeilKwX10) by the original author, Derek Brans
* [Interactive Demo](http://run.plnkr.co/plunks/e8MJAx/) with side by side comparisons of other tag writers
* [Documentation](https://github.com/krux/postscribe/tree/master/doc)
* Browse the [raw](https://github.com/krux/postscribe/blob/master/postscribe.js) or [annotated](http://krux.github.com/postscribe/doc/postscribe.html) source code.
# Getting Started
PostScribe overrides document.write. It is best and safest to use PostScribe after DOM is ready.
PostScribe overrides `document.write`. It is best and safest to use PostScribe after DOM is ready.
Include `./htmlParser/htmlParser.js` and `./postscribe.js` on your page. TODO: cdn for postscribe.min.js
## Installation
### Browser
If you just want to use the script without installing anything, use the following to load the script from *cdnjs*:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/postscribe/2.0.0/postscribe.min.js"></script>
```
### NPM
You can include `postscribe` using *npm*:
```console
npm install --save postscribe
```
Postscribe runs in browsers, so this assumes you're using a module bundler like [webpack](https://webpack.github.io/),
[Browserify](http://browserify.org/), [JSPM](http://jspm.io/) or [Rollup](http://rollupjs.org/) to consume CommonJS modules.
### Bower
You can include `postscribe` using *bower*:
```console
bower install --save postscribe
```
## Accessing
### ES6/ES2015
```javascript
import postscribe from 'postscribe';
```
### AMD
```javascript
define(['postscribe'], function(postscribe) {
});
```
### CommonJS
```javascript
var postscribe = require('postscribe');
```
## Usage
To append html to #mydiv:
postscribe('#mydiv', '<h1>Hello PostScribe</h1>');
```javascript
postscribe('#mydiv', '<h1>Hello PostScribe</h1>');
```
In general:
postscribe(element, html, options);
```javascript
postscribe(element, html, options);
```

@@ -41,50 +104,57 @@ * *element:* a DOM Element, jQuery object, or id selector (e.g. "#mydiv")

If you just want to mess around, include the js files at the top of an html page that contains the following:
<div id="mydiv"></div>
<script type="text/javascript">
postscribe('#mydiv', '<h1>Hello PostScribe</h1>');
</script>
```html
<div id="mydiv"></div>
<script type="text/javascript">
postscribe('#mydiv', '<h1>Hello PostScribe</h1>');
</script>
```
## How to use PostScribe to render an ad after load
## How to use postscribe to render an ad after load
Where normally you would have
<div id="ad"><h5>Advertisement</h5>
<script type="text/javascript">
// Build url params and make the ad call
document.write('<script src=doubleclick_url_with_params><\/script>');
</script>
</div>
```html
<div id="ad"><h5>Advertisement</h5>
<script type="text/javascript">
// Build url params and make the ad call
document.write('<script src=doubleclick_url_with_params><\/script>');
</script>
</div>
```
Instead, remove the ad call and close the div
<div id="ad"><h5>Advertisement</h5></div>
```html
<div id="ad"><h5>Advertisement</h5></div>
<script type="text/javascript">
// jQuery used as an example of delaying until load.
$(function() {
// Build url params and make the ad call
postscribe('#ad', '<script src=doubleclick_url_with_params><\/script>');
});
</script>
<script type="text/javascript">
// jQuery used as an example of delaying until load.
$(function() {
// Build url params and make the ad call
postscribe('#ad', '<script src=doubleclick_url_with_params><\/script>');
});
</script>
```
There are some hooks you may pass as the third argument. For example:
<script type="text/javascript">
// jQuery used as an example of delaying until load.
$(function() {
postscribe('#ad', '<script src=doubleclick_url_with_params><\/script>', {
done: function() {
console.info('Dblclick script has been delivered.');
}
});
});
</script>
```html
<script type="text/javascript">
// jQuery used as an example of delaying until load.
$(function() {
postscribe('#ad', '<script src=doubleclick_url_with_params><\/script>', {
done: function() {
console.info('Dblclick script has been delivered.');
}
});
});
</script>
```
See the beginning of [postscribe.js](./postscribe.js) for a complete list.
See the beginning of [postscribe.js](./src/postscribe.js) for a complete list.
# FAQ
##### Does it work with jQuery, Prototype, Backbone, Underscore, jQuery UI, YUI, mooTools, dojo, etc.?

@@ -94,26 +164,37 @@ Yep. It neither depends on nor conflicts with any of the existing popular javascript frameworks.

##### Does it work with another tag writing library on the page?
[Wat?](http://izit.org/sites/izit.org/files/1329697955565.jpg) No. Only one tag writer at a time.
No. Only one tag writer at a time.
# Who is using it
This project was originally developed at [Krux](http://www.krux.com) as part of its [SuperTag](http://www.krux.com/pro/whatwedo/manage/supertag/) product. There it was battle tested on high-profile sites like [The New York Times](http://www.nytimes.com), [The Wall Street Journal](http://online.wsj.com), [NBCU](http://www.nbcuni.com), and hundreds of others. It is actively maintained by Krux.
This project was originally developed at [Krux](http://www.krux.com) as part of its
[SuperTag](https://www.krux.com/data-management-platform-solutions/super-tag-management/) product.
There it has been battle tested on high-profile sites like [The New York Times](http://www.nytimes.com),
[The Wall Street Journal](http://online.wsj.com), [NBCU](http://www.nbcuni.com), and hundreds of others.
It is actively maintained by Krux.
# Browser Compatibility
Postscribe was designed to behave as closely to the native `document.write`/`innerHTML` does as possible, and we've taken great care to make sure that it works on every browser we can get our hands on. We expect it to work on every browser built after 2005. There are over 400 [unit tests](https://github.com/krux/postscribe/tree/master/test) that run on every commit, and we add more all the time. Postscribe is thoroughly tested and known to work well in the following browsers:
* Firefox - 3.6 and 4+
PostScribe was designed to behave as closely to the native `document.write`/`innerHTML` does as possible, and we've taken great care to make sure
that it works on every browser we can get our hands on. We expect it to work on every browser built after 2009. There are over
500 [unit tests](./test) that run on every commit. PostScribe is thoroughly tested and known to work well in the following browsers:
* Firefox 4+
* Chrome 10+
* Safari - 5.0+
* Opera - 10.0+
* Internet Explorer 7+ (as far as we know, it will work on IE 6, but we're trying to encourage [its death](http://ie6funeral.com), so we haven't tested it)
* iPhone/iPad and other webkit-based browsers
* Safari 5.0+
* Opera 10.0+
* Internet Explorer 8+
* iPhone/iPad and other WebKit-based browsers
Curious if a specific browser will work? [Run the tests yourself](http://krux.github.com/postscribe/test/test.html) and let us know if you see any failures.
Curious if a specific browser will work? [Run the tests yourself](http://krux.github.com/postscribe/test/test.html) and let us know if you see
any failures.
Note that we do not provide any support for Internet Explorer versions earlier than IE8.
# Alternatives
We've stood on the shoulders of giants with our work, and there are other alternative approaches to solve this problem. Shout out to the best ones we found:
We've stood on the shoulders of giants with our work, and there are other alternative approaches to solve this problem. Shout out to the best
ones we found:
* [writeCapture](https://github.com/iamnoah/writeCapture)
* [Ghostwriter](http://digital-fulcrum.com/ghostwriter/docs/files/ghostwriter-js.html) by Digital Fulcrum (it looks like they have removed references to it on their site?)
* Ghostwriter by Digital Fulcrum
* [ControlJS](http://stevesouders.com/controljs/) by [Steve Souders](http://stevesouders.com)

@@ -123,102 +204,85 @@

# Help/Bugs/Requests
# Help/Bugs/Requests
Have a problem? Need help? Would you like additional functionality added? We use github's ticket system for keeping track of these requests.
We ♥ bug reports.
Have a problem? Need help? Would you like additional functionality added? We use GitHub's ticket system for keeping track of these requests.
Please check out the [existing issues](https://github.com/krux/postscribe/issues), and if you don't see that your problem is already being
worked on, please [file a new issue](https://github.com/krux/postscribe/issues/new). The more information the better to describe your problem.
We ♥ [Jing](http://www.techsmith.com/jing.html) bug reports.
# Contributing
# Contributing
We ♥ [forks and pull requests](https://help.github.com/articles/using-pull-requests).
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for full details.
## Environment
To run the tests and static code analysis tools, you will need to have the following installed:
* nodejs (>=0.8) & npm - [Install Instructions](https://github.com/joyent/node/wiki/Installation)
* All other project dependencies are installed via npm with `npm install`
* [grunt](http://gruntjs.com) - a 'make' like tool for automating build, test, and other dev tasks
* [PhantomJS](http://phantomjs.org/) - A headless browser based on Webkit.
The project requires nodejs (>=5.6) and npm (>=3.6.0) for development. It has no runtime dependencies.
## Developing
## Pull Request Guidelines
Spaces, not tabs. 2 of them. [jQuery's style guide](http://docs.jquery.com/JQuery_Core_Style_Guidelines) covers just about everything else.
Please do not update 3rd-party libraries (qunit, jquery) or the dist directory. We have an internal process for doing this.
Check the code out and install the development dependencies using:
```console
npm install
```
## Issue Guidelines
Please include a [jsfiddle](http://jsfiddle.net) or [plunker](http://plnkr.co) that distills and reproduces the issue.
Try forking [this jsfiddle](http://jsfiddle.net/dbrans/Znpxv/). We've set everything up there for you so that you can reproduce your issue.
### Building
To build the code, run
## Testing
Using [travis-ci](https://travis-ci.org) and [grunt](http://gruntjs.com), the [Qunit](http://qunitjs.com) unit tests are run on every commit using PhantomJS to run the tests with a real browser.
```console
npm run build
```
Current Build Status: [![Build Status](https://travis-ci.org/krux/postscribe.svg?branch=master)](https://travis-ci.org/krux/postscribe)
### Linting
To run the tests:
We use ESLint and JSCS to do static analysis of the JavaScript and keep things smelling good. To run both, use:
`$ npm test`
```console
npm run lint
```
We use jshint to do static analysis of the javascript and keep things smelling good. To run jslint:
### Testing
`$ npm run lint`
Using [travis-ci](https://travis-ci.org), the [Qunit](http://qunitjs.com) unit tests are run on every commit using PhantomJS to run the tests
with a real browser.
**Pro Tip**: You can use TDD and have jslint and the tests run on every commit with:
To test the code locally, you can use:
`$ npm run tdd`
```console
npm test
```
Or, open the [test.html](./test/test.html) file in your web browser:
# History
Postscribe uses [software versioning standards](http://semver.org) as follows: major.new.maintenance[.trivial]. There are git tags for each release if you would like to see older versions.
```console
open test/test.html
```
##### 1.4.0
* Fix incomplete tags blocking UI thread
* beforeWriteToken hook
* Handle boolean attrs
* Comments fix
* Make autoFix a postscribe option
To run tests in Test-Driven-Development mode, where the test will be run after every change, use:
##### 1.3.2
* Screwed up the tagging. (automation coming soon...)
```console
npm run tdd
```
##### 1.3.0
* Adds hooks around queuing and stream starting.
To run the cross-browser tests, use:
##### 1.2.0
* Adds option to not overwrite doc.write while script[async] is loading.
```console
npm run test:cross-browser
```
##### 1.1.2
* iframe and textarea fix
## Issue Guidelines
##### 1.1.1
* Error handling mod
Please either add a failing [unit test](./test/unit) or include a [jsfiddle](http://jsfiddle.net) that distills and reproduces the issue.
##### 1.1.0
* major refactoring to simplify code and fix rare bugs related to script tag handling
* scripts are now written inline
Try forking [this jsfiddle](https://jsfiddle.net/postscribe/h1wnuk9h/). We've set everything up there for you so that you can reproduce your issue.
##### 1.0.5
* htmlParser performance fix
##### 1.0.3
* Test framework improvements
* Bug fixes
##### 1.0.2
* Documentation release
##### 1.0.1
* Documentation release
### 1.0.0 Initial open source release
[Released on Oct 12 2012](https://github.com/krux/postscribe/tree/version/1.0)
* Write tags asynchronously, yo. Initial release after 2+ years of development internally at [Krux](http://www.krux.com)
# License
We aim for you to use this inside your application, so we picked the least restrictive license we could find. MIT License - see [LICENSE](https://github.com/krux/postscribe/blob/master/LICENSE)
We aim for you to use this inside your application, so we picked the least restrictive license we could find.
See [LICENSE](LICENSE).

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc