Coder Social home page Coder Social logo

egaicebergwebdesign / scripts-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from swup/scripts-plugin

0.0 0.0 0.0 874 KB

:recycle: Swup plugin for auto re-running of included scripts.

Home Page: https://swup.js.org/plugins/scripts-plugin

License: MIT License

JavaScript 100.00%

scripts-plugin's Introduction

Swup Scripts Plugin

This plugin re-evaluates any <script> tags inside the <head> and/or <body> of your website on swup's contentReplaced event. This can be helpful if you don't have full control over the scripts included on your website and need to re-run certain scripts on every page view.

The plugin will ignore any script tags with the attribute [data-swup-ignore-script]. It is also necessary to add this attribute to the script from where you are initializing swup itself, to prevent the creation of multiple swup instances.

🚨Warning: This plugin is only intended as a last resort for projects with little control over what scripts are included. Re-running your scripts without first destroying any previous scripts can lead to memory leaks and in the worst case break your page. Use this at your own risk.

Installation

Install the plugin from npm and import it into your bundle.

npm install @swup/scripts-plugin
import SwupScriptsPlugin from '@swup/scripts-plugin';

Or include the minified production file from a CDN:

<script src="https://unpkg.com/@swup/scripts-plugin@1"></script>

Usage

To run this plugin, include an instance in the swup options.

const swup = new Swup({
  plugins: [new SwupScriptsPlugin()]
});

Options

head and body

The plugin provides two boolean options - head and body. Both are set to true by default. Set these to false to disable re-evaluating scripts globally in the head or body of your website.

new SwupScriptsPlugin({
  head: true,
  body: true
});

optin

In some situations, you might not have control over inserted scripts into the page (through Google Tag Manager, for example). In that case, setting the optin option to true will only reload the scripts explicitly marked with the [data-swup-reload-script] attribute.

new SwupScriptsPlugin({
  optin: false
});

scripts-plugin's People

Contributors

gmrchk avatar dependabot[bot] avatar hirasso avatar daun avatar thesved avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.