Basket.js: Script loader that caches scripts in localStorage

What is basket.js?

mmm, But why localStorage!

As you may know already that localStorage is API used in modern browsers to store data, Google and Bing told us that: There are performance benefits to caching assets in localStorage (especially on mobile) when compared to simply reading and writing from the standard browser cache.

How it work?

So the mean idea, That it request scripts via XHR — which means if you need to test it locally you will need to run it from localserver — then store them in browser’s localStorage and next time page loads scripts, it loads from localStorage directly!

Show me some code!

As you can know from installation guide:

Basket.js sample
jQuery saved in localStorage!
  • EXPIRE: expire time in hours:
basket.require({ url: ‘jquery.min.js’, expire: 24})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store