• Stars
    star
    176
  • Rank 216,987 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

🌈 A Webpack plugin generates a browser-side standalone script that detects browser compatibility based on `Browserslist` and prompts website users to upgrade it.

Obsolete Webpack Plugin

npm npm npm npm node npm licenses

Introduction 🌟

A Webpack plugin generates a browser-side standalone script that detects browser compatibility based on Browserslist and prompts website users to upgrade it.

Motivation 💥

In modern front-end development, we use toolchain to convert next JavaScript version into a backwards compatible version of JavaScript that works in older browser environment. For next syntax features, such as Object Rest/Spread Properties, Exponentiation Operator, we can transform all of them through AST parser. For next built-in features, such as Promise, WeakMap, String.prototype.padstart, we can provide pollyfills that mimic native functionality. However, for some browser only features, such as Service Worker, WebAssembly, CSS Grid Layout, no polyfills support these or partially support. In the worst case, our users who use old browsers open a website but catch a sight of blank page. It may be a bad network condition, may be syntax parsing error, may be built-in losing. But they must not realize that the browser they using does not meet the requirements of our website target. Therefore, we need a mechanism to notify that they should upgrade their browser before accessing content. Thus, this plugin borns.

Getting Started

Prerequisite

  • Node >=8.3.0
  • Webpack 4.x

Installation

$ npm i -D obsolete-webpack-plugin

Basic Usage

Apply the plugin in your Webpack configuration, often used together with html-webpack-plugin. By the way, the putting order of plugins is irrelevant.

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ObsoleteWebpackPlugin = require('obsolete-webpack-plugin');

module.exports = {
  // ...
  plugins: [
    // ...
    new HtmlWebpackPlugin(),
    new ObsoleteWebpackPlugin()
  ]
};

Best Practice

To improve first page load speed, you should always reduce render-blocking scripts as far as possible. For non-critical script, it's best to mark them with the async attribute. Thanks to script-ext-html-webpack-plugin, we are able to fulfill this goal easily.

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ObsoleteWebpackPlugin = require('obsolete-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');

module.exports = {
  // ...
  plugins: [
    new HtmlWebpackPlugin(),
    new ObsoleteWebpackPlugin({
      name: 'obsolete'
    }),
    new ScriptExtHtmlWebpackPlugin({
      async: 'obsolete'
    })
  ]
};

Configuration 📖

Options

Name Type Default Description
name string 'obsolete' The chunk name.
template string '<div>Your browser is not supported. <button id="obsoleteClose">&times;</button></div>' The prompt html template. It accepts any document fragment. E.g., '<style>...</style><div>...</div><script>...</script>'. Specially, the template will be removed when a node with attribute id="obsoleteClose" is clicked.
position string 'afterbegin' If set 'afterbegin', the template will be injected into the start of body.
If set 'beforeend', the template will be injected into the end of body.
browsers string[] Browsers to support, overriding global browserslist configuration.
promptOnNonTargetBrowser boolean false If the current browser useragent doesn't match one of the target browsers, it's considered as unsupported. Thus, the prompt will be shown. E.g., your browserslist configuration is ie > 8, by default, the prompt won't be shown on Chrome or Safari browser. E.g., your browserslist configuration is ie > 8, by default, the prompt won't be shown on Chrome or other browsers. Another e.g., your browserslist configuration is chrome > 80, by default, the prompt won't be shown on IE or other browsers.
promptOnUnknownBrowser boolean true If the current browser useragent is unknown, the prompt will be shown.

Demonstration 🎨

Browser Support 👓

The name matches Browserslist queries.

Desktop

IE Edge Chrome Safari Firefox Opera Electron

Mobile

ChromeAndroid Android
(5+, WebView)
iOS
(OS)

FAQ 🍵

Q: Does this plugin support Yandex, Maxthon, UC or QQ browser?

A: Yep. This plugin supports those browsers based on the mainstream browser kernel, such as Chromium based browser, Mozilla based browser. In other words, Chrome >= 30 will be also applied to Yandex browser, ChromeAndroid >= 30 will be also applied to Android UC browser.

Q: Does plugin work in IE 6?

A: Yep. This plugin supports browsers that implement the full ES3 spec. Although the source code is ES2015+, it will be compiled and shimmed to the target environment eventually.

More Repositories

1

element

A Vue.js 2.0 UI Toolkit for Web
Vue
54,115
star
2

mint-ui

Mobile UI elements for Vue.js
Vue
16,570
star
3

node-interview

How to pass the Node.js interview of ElemeFE.
HTML
10,407
star
4

v-charts

基于 Vue2.0 和 ECharts 封装的图表组件📈📊
JavaScript
6,802
star
5

vue-amap

🌍 基于 Vue 2.x 和高德地图的地图组件
JavaScript
3,320
star
6

element-react

Element UI
JavaScript
2,832
star
7

vue-infinite-scroll

An infinite scroll directive for vue.js.
JavaScript
2,828
star
8

page-skeleton-webpack-plugin

Webpack plugin to generate the skeleton page automatically
JavaScript
2,748
star
9

cooking

👨‍🍳 更易上手的前端构建工具
JavaScript
1,948
star
10

node-practice

Node.js 实践教程
JavaScript
1,374
star
11

restc

A server-side middleware to visualize REST requests.
HTML
1,348
star
12

react-amap

基于 React 封装的高德地图组件。AMap Component Based On React.
JavaScript
1,031
star
13

vue-swipe

A touch slider for vue.js.
Vue
929
star
14

vue-desktop

A UI library for building admin panel website.
Vue
550
star
15

element-angular

Element for Angular
TypeScript
522
star
16

hire

寻找热爱生活,把世界变的更好的人
468
star
17

keynote

大前端分享会公开演示文稿
HTML
335
star
18

image-cropper

A image cropper for cropping user avatar, no dependencies.
JavaScript
311
star
19

postcss-salad

沙拉是一个能够帮助你写出更加简洁、优雅的CSS的样式解决方案
CSS
275
star
20

vscode-element-helper

VSCode-Element-Helper is a VS Code package for Element-UI.
TypeScript
240
star
21

smart-gesture

这是一个小型手势组件,支持普通的方向手势和自定义图形手势,兼容PC端和移动端,可以非常方便的用它实现一些酷炫的手势操作。
JavaScript
238
star
22

vue-msgbox

A message box (like Sweet Alert) for vue.js.
JavaScript
236
star
23

bowl

🍚 static resources front-end storage solving strategy
JavaScript
227
star
24

style-guide

style guide for everyone
226
star
25

element-dashboard

element dashboard
Vue
222
star
26

weex-vue-starter-kit

weex starter kit in vue to use weexpack & weex both.(support hot-reload)
JavaScript
179
star
27

vue-toast-mobile

A mobile toast plugin for vue.js
HTML
144
star
28

eslint-config-elemefe

JavaScript
136
star
29

vue-img

hash2path wrapper for vue.js
JavaScript
117
star
30

mongodb-doc-cn

Mongodb 中文文档, 在线阅读 ->
101
star
31

Hachart

HaHa, this is a flowchart generator.
JavaScript
92
star
32

vue-popup

A popup mixin for vue.js
JavaScript
77
star
33

element-helper

🚀 Element-Helper is a Atom package for Element-UI.
JavaScript
75
star
34

crayfish

基于 CDN 的配置管理系统
JavaScript
58
star
35

webspoon

这是一个 Web 前端工程化的工具包
JavaScript
45
star
36

random

一个随机分组的小工具
HTML
44
star
37

ng-staticize

Staticize your angular template. Zero watcher and fast as template engine.
JavaScript
38
star
38

v-datepicker

基于Vue指令实现的一个日历选择器控件
Vue
33
star
39

clouding

前端「零机器」部署方案
32
star
40

WAI-ARIA-Practices

ARIA实践指南(中文版)
25
star
41

react-native-smart-gesture

smart-gesture for react-native.
JavaScript
24
star
42

image-cropper-touch

A image cropper for mobile device.
JavaScript
15
star
43

vue-smart-gesture

smart-gesture for vue.
JavaScript
15
star
44

vue-desktop-starter

A starter for vue-desktop.
JavaScript
13
star
45

hasaki

A file generator for easy writing your application.
JavaScript
8
star
46

react-smart-gesture

smart-gesture for react.
JavaScript
7
star
47

appCacheReload

JavaScript
5
star
48

element-migration-helper

CLI tool to aid in migration from Element-UI 1.x to 2.0
JavaScript
3
star
49

snapshot

JavaScript
2
star
50

pocket-noodles

A WEB API CACHING SOLUTION
JavaScript
2
star
51

sip

1
star