Lúcuma
Cross-Domain CSS Long Polling with Parallel Processing!
- Small ~ @6.9kb ~2.8kb gzip'd
- Cross-browser ~ IE6+, FF2+, Safari3+, iPhone
- No plugins ~ Flash, Silverlight, etc. Pure Javascript & CSS
- Cross-domain ~ Say goodbye to the Same-Origin Policy
- Simple ~ nuff said!
Lúcuma, or eggfruit (Pouteria lucuma) is a subtropical fruit commonly found in Peru, Ecuador, and Chile. It belongs to the same order as the kiwi, brazil nut, and blueberry. This orange-green fruit is quite nutritous, containg a great deal of vitamins and minerals. Although you may not have heard of it, Lúcuma is actually the most popular flavor of ice cream in Peru, exceeding strawberry, chocolate, and vanilla.
What is Lúcuma?
Version: 1.0.0
Lúcuma is a very simple tool that makes great use of nb.io's CSSHttpRequest. This extends compatibility of Long Polling to many older browsers including IE6, and even some mobile browsers! Lúcuma is designed to make it simple to develop faux real-time website applications. It is strongly encouraged that you check out the examples below.
Want to get started?
first you need to declare an instance of Lucuma, `connection = new Lucuma("url");`
The result is an object with the below data members:
-
(function) _uriencodes the queries object into a GET uri string i.e. ?one=two&red=blue
-
(unsigned int) attemptsthe number of times a connection to the server was attempted
-
(boolean) cachewhether or not the result should be cached
-
(function) callbackcalled when data is returned from the server, however do NOT override this, this calls onresponse as well as some other functions
-
(object) connectionestablish, terminate, suspend, and resume. Note: terminate cannot be undone, while suspend can by resume
-
(float) durationthe time that should be waited for another call to be made to the server
-
(function) getConnectionByIdhas one parameter, the id. returns the instance of lucuma with that id
-
(int) idthis instance's id
-
(function) onresponsecalled when data is returned from the server
-
(function) onterminationcalled with the instance is terminated
-
(function) passesthe number of times a connection was successfully made
-
(boolean) pausedwhether or not the instance is paused. Note: use this.connection.suspend, do NOT set paused to true
-
(object) queriesthe object that contains all of the queries to be encoded in the url","(function) request
-
(function) requestdo not override, this function calls CSSHttpRequest for the given url with queries
-
(boolean) terminatedwhether or not the connection if terminated
-
(string) urlpassed in the declaration of the instance, but editable, the url to be polled
Lets see it in action!
Here are two examples, one is a BBC Breaking News Agigator and the other is a chat web app.
Need to see some code?
It is this simple:
Cons:
- It's no WebSocket ~ (Lúcuma does not offer a real full-duplex connection)
- Server-side configuration ~ (You'll need to configure your backend to output your data correctly, and for assistance I recommend you check out nb.io for exmaples)
- GET only ~ (Lúcuma cannot use the POST, DELETE, or PUT method)
window.onload = function () { Connection = new Lucuma("news.php"); Connection.onresponse = function (response) { alert(response); }; Connection.connection.establish(); };
So why should I use Lúcuma?
- Compatibility! ~ (IE6+, FF2+, Opera9+, Safari3+...)
- Parallel Processing! ~ (Most browsers can handle multiple CSS requests simultaneously, even IE)
- Cross-Domain! ~ (Because we are using CSS, the Same-Origin Policy does not apply)
- Small! ~ @6.9kb ~2.8kb gzip'd
- Simplicity! ~ enough said!