Convert Figma logo to code with AI

NekR logooffline-plugin

Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)

4,515
293
4,515
109

Top Related Projects

make your Next.js application work offline using service workers via Google's workbox

Webpack plugin that generates a service worker using sw-precache that will cache webpack's bundles' emitted assets. You can optionally pass sw-precache configuration options to webpack through this plugin.

4,883

✈️ Easily create sites that work offline as well as online

Quick Overview

Offline Plugin is a Webpack plugin that automatically creates a ServiceWorker for your application, enabling offline functionality and caching of assets. It's designed to work seamlessly with various Webpack configurations and provides a simple way to add offline support to web applications.

Pros

  • Easy integration with Webpack projects
  • Automatic generation of ServiceWorker
  • Configurable caching strategies
  • Supports various asset types (JavaScript, CSS, images, etc.)

Cons

  • May require additional setup for complex applications
  • Limited customization options compared to manually writing a ServiceWorker
  • Potential conflicts with other ServiceWorker implementations
  • Learning curve for developers unfamiliar with ServiceWorkers

Code Examples

  1. Basic configuration:
const OfflinePlugin = require('offline-plugin');

module.exports = {
  // ... other webpack config
  plugins: [
    new OfflinePlugin()
  ]
};
  1. Custom caching strategy:
new OfflinePlugin({
  caches: {
    main: [':rest:'],
    additional: ['*.chunk.js']
  },
  safeToUseOptionalCaches: true
})
  1. Excluding specific assets:
new OfflinePlugin({
  excludes: ['**/.*', '**/*.map', 'stats.json']
})

Getting Started

  1. Install the plugin:

    npm install offline-plugin --save-dev
    
  2. Add the plugin to your Webpack configuration:

    const OfflinePlugin = require('offline-plugin');
    
    module.exports = {
      // ... other webpack config
      plugins: [
        new OfflinePlugin()
      ]
    };
    
  3. Include the runtime in your entry point:

    import * as OfflinePluginRuntime from 'offline-plugin/runtime';
    OfflinePluginRuntime.install();
    
  4. Build your project with Webpack, and the ServiceWorker will be automatically generated and included in your output.

Competitor Comparisons

make your Next.js application work offline using service workers via Google's workbox

Pros of next-offline

  • Specifically designed for Next.js applications, providing seamless integration
  • Simpler configuration process, with sensible defaults for Next.js projects
  • Automatic handling of dynamic routes and API routes in Next.js

Cons of next-offline

  • Limited to Next.js projects, less versatile for other frameworks or vanilla JS
  • Fewer customization options compared to offline-plugin's extensive configuration
  • May require additional setup for complex caching strategies

Code Comparison

offline-plugin configuration:

new OfflinePlugin({
  safeToUseOptionalCaches: true,
  caches: {
    main: ['index.html', 'app.js', 'app.css'],
    additional: ['*.chunk.js']
  },
  ServiceWorker: {
    events: true,
    navigateFallbackURL: '/'
  }
})

next-offline configuration:

const withOffline = require('next-offline')

module.exports = withOffline({
  workboxOpts: {
    swDest: 'static/service-worker.js',
    runtimeCaching: [
      {
        urlPattern: /^https?.*/,
        handler: 'NetworkFirst'
      }
    ]
  }
})

Both plugins aim to provide offline capabilities, but next-offline offers a more streamlined approach for Next.js projects, while offline-plugin provides greater flexibility for various web applications.

Webpack plugin that generates a service worker using sw-precache that will cache webpack's bundles' emitted assets. You can optionally pass sw-precache configuration options to webpack through this plugin.

Pros of sw-precache-webpack-plugin

  • Integrates seamlessly with webpack, making it easier to use in webpack-based projects
  • Offers more granular control over caching strategies for different types of assets
  • Provides a simpler configuration process for basic use cases

Cons of sw-precache-webpack-plugin

  • Less flexible for complex offline scenarios compared to offline-plugin
  • Lacks some advanced features like AppCache fallback and multiple caching strategies
  • May require more manual configuration for advanced use cases

Code Comparison

offline-plugin:

new OfflinePlugin({
  caches: {
    main: [':rest:'],
    additional: ['*.chunk.js']
  },
  ServiceWorker: {
    events: true
  },
  AppCache: { events: true }
})

sw-precache-webpack-plugin:

new SWPrecacheWebpackPlugin({
  cacheId: 'my-project-name',
  filename: 'service-worker.js',
  staticFileGlobs: ['dist/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'],
  minify: true
})

Both plugins aim to provide offline capabilities for web applications, but they differ in their approach and feature set. offline-plugin offers more advanced features and flexibility, while sw-precache-webpack-plugin provides easier integration with webpack and simpler configuration for basic use cases.

4,883

✈️ Easily create sites that work offline as well as online

Pros of UpUp

  • Simpler setup and configuration, making it easier for beginners to implement offline functionality
  • Lightweight and focused specifically on offline content caching
  • Clear and concise documentation with straightforward examples

Cons of UpUp

  • Less flexible and customizable compared to offline-plugin
  • Limited to basic offline caching scenarios, may not be suitable for complex applications
  • Fewer advanced features and integration options with build tools

Code Comparison

UpUp:

upup.start({
  'content-url': 'offline.html',
  'assets': ['img/logo.png', 'css/style.css', 'js/app.js']
});

offline-plugin:

new OfflinePlugin({
  caches: {
    main: ['index.html', '*.js', '*.css'],
    additional: ['*.png', '*.jpg']
  },
  ServiceWorker: {
    events: true
  }
})

UpUp provides a simpler API for basic offline functionality, while offline-plugin offers more granular control and integration with webpack. offline-plugin is better suited for larger, more complex applications, whereas UpUp is ideal for smaller projects or quick implementations of offline capabilities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README



offline-plugin logo

offline-plugin for webpack

backers sponsors npm npm


This plugin is intended to provide an offline experience for webpack projects. It uses ServiceWorker, and AppCache as a fallback under the hood. Simply include this plugin in your webpack.config, and the accompanying runtime in your client script, and your project will become offline ready by caching all (or some) of the webpack output assets.

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site.
Become a sponsor

Install

npm install offline-plugin [--save-dev]

Setup

First, instantiate the plugin in your webpack.config:

// webpack.config.js example

var OfflinePlugin = require('offline-plugin');

module.exports = {
  // ...

  plugins: [
    // ... other plugins
    // it's always better if OfflinePlugin is the last plugin added
    new OfflinePlugin()
  ]
  // ...
}

(and optionally configure with options)

Then, add the runtime into your entry file (typically main entry):

require('offline-plugin/runtime').install();

ES6/Babel/TypeScript

import * as OfflinePluginRuntime from 'offline-plugin/runtime';
OfflinePluginRuntime.install();

For more details of usage with TypeScript see here

offline-plugin isn't working?

:information_source: Troubleshooting | FAQ

Docs

Examples

Articles

Options

All options are optional and offline-plugin can be used without specifying them.

See all available options here.

Who is using offline-plugin

Projects

PWAs

If you are using offline-plugin, feel free to submit a PR to add your project to this list.

Like offline-plugin?

Support it by giving feedback, contributing, becoming a backer/sponsor or just by 🌟 starring the project!

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Contribution

See CONTRIBUTING

License

MIT
Logo

CHANGELOG

CHANGELOG

NPM DownloadsLast 30 Days