New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

criticaljs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

criticaljs - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

4

dist/criticaljs.min.js
/**
* criticaljs - CriticalJS is a JavaScript library which enables you to improve the perceived performance of your site
* @version v0.0.2
* @version v0.0.3
* @link https://github.com/jonathan-fielding/criticaljs
* @license MIT
*/
"use strict";!function(){function e(){r(),n()}function t(){var e=document.createElement("script");e.id="deferredjs",e.src=o,document.body.appendChild(e)}function n(){"complete"!==document.readyState?window.addEventListener("load",t,!1):t()}function r(){for(var e=document.querySelectorAll("[data-deferred]"),t=0;t<e.length;t++){var n=e[t],r=n.getAttribute("data-deferred");if(r.length){r=r.split(" ");for(var i=0;i<r.length;i++)d(n,r[i])}}}function d(e,t){e.addEventListener(t,i(a,[t]))}function i(e,t){return function(){e.apply(this,t)}}function a(e){var t=this.getAttribute("data-triggered-events"),n=t?t.split(" "):[];-1===n.indexOf(e)&&n.push(e),this.setAttribute("data-triggered-events",n.join(" ")),"true"===this.getAttribute("data-prevent-default")&&event.preventDefault()}var u={},c=document.querySelector("script[data-deferredjs]"),o=c.getAttribute("data-deferredjs");u.deferred=function(e,t,n){var r=n||!0,d=e.getAttribute("data-triggered-events"),i=d?d.split(" "):[];return"undefined"==typeof t?i:-1!==i.indexOf("click")?(r&&(i.splice(i.indexOf("click"),1),e.setAttribute("data-triggered-events",i.join(" "))),!0):!1},document.addEventListener("DOMContentLoaded",e),window.criticaljs=u}();
"use strict";!function(){function e(){r(),n()}function t(){var e=document.createElement("script");e.id="deferredjs",e.src=c,document.body.appendChild(e)}function n(){"complete"!==document.readyState?window.addEventListener("load",t,!1):t()}function r(){for(var e=document.querySelectorAll("[data-deferred]"),t=0;t<e.length;t++){var n=e[t],r=n.getAttribute("data-deferred");if(r.length){r=r.split(" ");for(var i=0;i<r.length;i++)d(n,r[i])}}}function d(e,t){e.addEventListener(t,i(a,[t]))}function i(e,t){return function(){e.apply(this,t)}}function a(e){var t=this,n=t.getAttribute("data-triggered-events"),r=n?n.split(" "):[];-1===r.indexOf(e)&&r.push(e),t.setAttribute("data-triggered-events",r.join(" ")),"true"===t.getAttribute("data-prevent-default")&&event.preventDefault()}var u={},o=document.querySelector("script[data-deferredjs]"),c=o.getAttribute("data-deferredjs");u.deferred=function(e,t,n){var r=n||!0,d=e.getAttribute("data-triggered-events"),i=d?d.split(" "):[];return"undefined"==typeof t?i:-1!==i.indexOf(t)?(r&&(i.splice(i.indexOf(t),1),e.setAttribute("data-triggered-events",i.join(" "))),!0):!1},document.addEventListener("DOMContentLoaded",e),window.criticaljs=u}();
{
"name": "criticaljs",
"version": "0.0.2",
"version": "0.0.3",
"description": "CriticalJS is a JavaScript library which enables you to improve the perceived performance of your site",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,2 +0,2 @@

# CriticalJS
# CriticalJS 0.0.3
[![Build Status](https://travis-ci.org/jonathan-fielding/criticaljs.svg)](https://travis-ci.org/jonathan-fielding/criticaljs)

@@ -8,7 +8,8 @@

## Getting setup
## Usage
The simplest way to use CriticalJS is to include the critical.js file in your page and then specify a data
attribute with the location of the main JavaScript that is to be defered.
### Getting setup
The simplest way to use CriticalJS is to include the critical.min.js file in your page and then specify a data attribute with the location of the main JavaScript that is to be deferred.
```

@@ -18,5 +19,21 @@ <script src="criticaljs.min.js" data-deferredjs="main.js"></script>

Having included CriticalJS in the page and set the path to the main JavaScript that is being defered, we now need to setup elements which we intend to defer events for. In order to do this we need to set a data attribute ```data-deferred``` specifying the events to be deffered. This accepts any of the event types you would normally attach using ```addEventListener``` such as ```click``` and ```touchstart```.
```
<button data-deferred=“click touchstart”>
Click Me
</button>
```
### Triggering deferred events
Once our main JavaScript has loaded, you will need to determine whether a user has interacted with an element so that you are able to handle it.
```
criticaljs.deferred(element, 'click')
```
## Browser Support
We are currently targetting supporting Firefox, Android Browser, Chrome, Safari, Opera and Internet Explorer 9+.
We are currently targetting supporting Firefox, Android Browser, Chrome, Safari, Opera and Internet Explorer 9+. Testing is in the early stages and any help would be welcomed.

@@ -23,0 +40,0 @@ ## Contributing

@@ -20,6 +20,6 @@ 'use strict';

if (triggeredEventsArray.indexOf('click') !== -1) {
if (triggeredEventsArray.indexOf(event) !== -1) {
if (removeDeferred) {
triggeredEventsArray.splice(triggeredEventsArray.indexOf('click'), 1);
triggeredEventsArray.splice(triggeredEventsArray.indexOf(event), 1);
el.setAttribute('data-triggered-events', triggeredEventsArray.join(' '));

@@ -84,3 +84,5 @@ }

function handleDeferred(type) {
var triggeredEvents = this.getAttribute('data-triggered-events');
var el = this;
var triggeredEvents = el.getAttribute('data-triggered-events');
var triggeredEventsArray = triggeredEvents ? triggeredEvents.split(' ') : [];

@@ -92,5 +94,5 @@

this.setAttribute('data-triggered-events', triggeredEventsArray.join(' '));
el.setAttribute('data-triggered-events', triggeredEventsArray.join(' '));
if (this.getAttribute('data-prevent-default') === 'true') {
if (el.getAttribute('data-prevent-default') === 'true') {
event.preventDefault();

@@ -97,0 +99,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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