WickyNilliams / headroom.js

Give your pages some headroom. Hide your header until you need it
https://wicky.nillia.ms/headroom.js/
MIT License
10.86k stars 824 forks source link

Feature/simplify api #352

Closed WickyNilliams closed 5 years ago

WickyNilliams commented 5 years ago

This is a breaking change, which simplifies the external API and the internals.

The external API has changed in the following way.

Before:

import Headroom from "headroom.js";

var hr = new Headroom(element, options);
hr.init();
hr.destroy();

After:

import headroom from "headroom.js";

var hr = headroom(element, options);
hr.destroy();

Dropping usage of classes has resulted in ~20% file size saving before gzip, and ~10% after gzip.

Before:

┌───────────────────────────────────────┐
│                                       │
│   Destination: dist/headroom.min.js   │
│   Bundle Size:  4.26 KB               │
│   Gzipped Size:  1.37 KB              │
│   Brotli size: 1.32 KB                │
│                                       │
└───────────────────────────────────────┘

After:

┌───────────────────────────────────────┐
│                                       │
│   Destination: dist/headroom.min.js   │
│   Bundle Size:  3.45 KB               │
│   Gzipped Size:  1.22 KB              │
│   Brotli size: 1.2 KB                 │
│                                       │
└───────────────────────────────────────┘