Albin Larsson: Blog

Culture, Climate, and Code

The AWW Library

7th May 2014

I’m not a big fan of jQuery, but I do many AJAX calls. Most time I just write the AJAX calls straight into my code, it works fine! :-) Some days ago I did some work with WebWorkers(Get it, it’s good stuff), as in many of my tests I’m adding jQuery to do things just a bit faster(by that I mean my coding speed). I ran into the issue that I can’t use jQuery in a WebWorker, and writing it the XMLHttpRequest way for all my future WebWorker tests? No thanks.

You already know what I did next.

I do now that there is tons of small AJAX libraries in the wild, but not to many that’s below two kb in size, works with WebWorkers and most important made by me ;-)

AWW

Minimal AJAX requests for WebWorker usage.

Say hello to AWW.ajax(), AWW.get() and AWW.post().

Simple example:

AWW.ajax({
  url: "http://filltext.com/?rows=10&business={business}&location={city}&pretty=true",
  success: function(data) {
    document.getElementById('results').innerHTML = data;
  }
});

WebWorker example:

importScripts('../../aww.js');

getData();
setInterval(getData, 1000);

function getData() {
  AWW.ajax({
    url: "http://filltext.com/?rows=10&business={business}&location={city}&pretty=true",
    success: function(data) {
      postMessage(data);
    }
  });
}

For the full working examples see the “tests”(NOTE: You will need a web server to run the WebWorker example).

It’s very easy to learn just by reading the code.

If you would like to explore AWW a bit deeper check it out on Github.

Related posts