Git Product home page Git Product logo

websocket-script-loader's Introduction

Websocket script loader

Load scripts dynamicly with websocket instead of individual http-requests.

This code is not stable, just a demo to verify that it works

This is not optimal, it does not work with the browsers cache so this is someting that needs to be implemented by the site owner

Usage

The base stuff is really simple:

  1. Ask the server for a script file
  2. Server finds that script file and sends the contents
  3. Client receives the script file contents and adds it to the DOM

Server

The server is done using node with the ws plugin.

$ node server.js

Client

On the client site you need to include client.js, check the very simple test.html

<script src="client.js"></script>

This will just do the demo, downloading jquery-1.11.0.min.js and alert.js from the server and add them to the DOM in script elements.

jquery-1.11.0.min.js is jQuery downloaded and stored on the server. alert.js is just an example, it alerts:

Well hello, websocket dynamic script loading worked!

Look at your html and you will find the following:

<script data-script-url="js/jquery-1.11.0.min.js" type="text/javascript">jquery content...</script>
<script data-script-url="js/alert.js" type="text/javascript">alert("Well hello, websocket dynamic script loading worked!");</script>

websocket-script-loader's People

Contributors

halmhatt avatar

Watchers

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