GithubHelp home page GithubHelp logo

project-tf / watchem.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from duzun/watchem.js

0.0 3.0 0.0 196 KB

Live reload implementation in one script

License: MIT License

JavaScript 100.00%

watchem.js's Introduction

watchem.js

@version 0.3.2

A very simple script to watch for .js & .css files present in DOM over AJAX and reload the page/CSS when changes are detected.

Usage

At the boottom of you <body>, after all <script> tags add this:

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

You can add more files to watchem or exclude some by:

var watchemToo = window.watchemToo || (window.watchemToo = {});
watchemToo['/assets/someModule.js'] = true; // watch
watchemToo['/assets/jquery.js']  = false; // don't watch

How it works

It makes HEAD requests to the server in the specified interval and compares ETag or Last-Modified and Content-Length and Content-Type header with the stored value.

If server does not return any of the tracked headers, it makes GET requests (which are more expensive) and compares the contents of the file.

When should I use it

I find it best suited for TDD / BDD and for designing using HTML & CSS.

I've built this script to automatically run Jasmine specs inside a Chrome Extension on source files change (do you know about Karma?), but it can be successfully used for any web app.

For advanced stuff I recomend BrowserSync (requires Node.js).

Dependencies

Requires one of:

window.jajax = function (opt, suc, err) {
    return jQuery.ajax(opt).done(suc).fail(err)
}

Browser Compatibility

I've tested it on Google Chrome 39-43, Safari 5.1-8.0 and Firefox 36-38 so far. I don't know when I would need to use it in other browser, but PRs are welcome.

Alternatives

watchem.js's People

Contributors

duzun avatar

Watchers

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