Giter VIP home page Giter VIP logo

script-loder's Introduction

script-loder

scriptタグをJSから動的に読み込む。

概要

JavaScript実行時に動的に外部のjsファイルを読み込みむモジュールです。 スクリプトをjsファイルに分けて管理したいけれど、ビルドツールが使えない時があったので作成しました。 依存関係を解決するために、直列に読み込むことを可能にしています。

使い方の例

sl.setSrc('https://code.jquery.com/jquery-3.3.1.js', 'parallel');
sl.setSrc('https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore.js', 'parallel');
sl.setSrc('https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js', 'series');
sl.setSrc('https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.js', 'series');
sl.load(
() => {
    console.log('success!');
},
() => {
    console.log('error!');
});

簡単な仕様

setSrcメソッドで読み込みたいソースを指定します。第1引数が読み込みたいソース、第2引数が読み込み方を直列にするか並列にするか指定できます。 以下の順で読み込まれます。

並列指定したソース → 直列指定したソース

sl.stSrc('xxxx.js', 'parallel');
sl.stSrc('xxxx.js', 'series');

loadメソッドで読み込みを実行します。第1引数が成功時、第2引数がエラー発生時に実行されるコールバックです。

sl.load(
() => {
    console.log('success!');
},
() => {
    console.log('error!');
});

script-loder's People

Contributors

shoya123 avatar

Watchers

James Cloos avatar  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.