proxyload v0.1.5
ProxyLoad
ProxyLoad rewrites DOM elements and point their src attribute to a given url.
Goal is to quickly load big assets from a local proxy without worrying about network speed.
For example, let's suppose you have a nice presentation website.
You have lots of big assets like videos or detailed pictures.
The D-Day everything must run smoothly even if customer's network is slow.
You can't download the whole website because it's generated by some obscure and forbidden backend.
With proxyload, you only download big assets, serve them locally and add data-proxyload
to their HTML elements.
It is certainly a very specific use case. I hope you can find others :)
Installing
- npm:
npm install proxyload
- github: https://cdn.rawgit.com/nleof/proxyload/master/proxyload.min.js
Usage
You can can the attribute data-proxyload to your DOM elements.
<video src="http://slowdomain.tld/assets/test.mp4" data-proxyload />
<script type="application/javascript" src="proxyload.min.js"></script>
<script>
(function () {
ProxyLoad({
url: 'http://localhost:3000'
});
})();
</script>
Will rewrite the video element to:
<video src="http://localhost:3000/slowdomain.tld/assets/test.mp4" data-proxyload />
You can also change the default selector [data-proxyload]
with:
<script>
(function () {
ProxyLoad({
url: 'http://localhost:3000',
selector: '*' // any valid CSS selector
});
})();
</script>
Serving assets
You can use caddy or http-server to quickly serve your assets.
Don't forget to enable CORS on your server.