JavaScript Tutorials
JavaScriptjsCron for Time Based Applications
Every now and then a simple yet highly useful JavaScript library comes out to assist Ajax and JavaScript developers in building applications. Although the library might not be perfect on its first release, the fact the robust support and feedback from the development community is there makes the specific library considerably improve and applicable to different browsers. As long as the library is hosted, it slowly develops as it adapts to latest technology.
Such is the case for jsCron, a simple JavaScript library that could become a nifty addition to your online application. In gist, jsCron will help you execute a code not by actions but by time. It could be a simple prompt or if your server could really push it, a function so that drastic changes will happen in your online application without the prompt of the user. This simple application was developed by Andrés Nieto and became a popular library since it was released. Although the idea of time based functions is already available in JavaScript, jsCron makes everything simpler.
According to the developer, your code will look like this. Of course this will be expandable if you want to add more functions for the library.
1.
2. // Función hola();
3. function hola() {
4. alert("Hola");
5. }
6.
7. // Tarea programada
8. jsCron.set("35 17 * * * hola()");
9.
(Note: it is in Spanish as this was published on the native language of the developer)
Pressure on Server
You will immediately notice that the code is not that difficult to execute. However, the efficiency of this function largely depends on the ability of the server and the client side to work together. If you are integrating this function that requires server push, you may have trouble setting the execution time.
Although the said function will execute without the user’s aid, the actual execution might not be as expected. The accuracy of execution when done on the server side is based on traffic and the ability of the server to handle data requests.
This means that if you are planning opens the application in public and expects a lot of traffic; make sure that your server could handle data requests. If you cannot do this, better discard the idea for now. The idea is great but the execution in the server side is still a little bit theoretical.
On the other hand, if you are using the function on the client side, it is very ideal to stick to the basics and its original purpose. You may have noticed that the demonstration or sample code is about prompting the user “Hola” after the said time.
Expanding it further to other functions will be ideal however it could jeopardize your application. Again, it might suffer from delay because there are too many functions to be considered with jsCron. jsCron is practically what it is according to demonstration – a simple time based application used to prompt the user after sometime. Although simple, this will save you a lot of time in checking the application from time to time.
Sponsored Links
