Showing posts with label html5. Show all posts
Showing posts with label html5. Show all posts

Why is HTML5 becoming popular as a hybrid mobile app development tool?


Why is HTML% becoming popular?

Recent scenario of hybrid mobile app development shows advanced technology in mobile devices that are rapidly increasing these days. App developers have initiated to create mobile apps with sophisticated technologies that ensure amazing visual features and high-functionality.

HTML5 plays a vital role among mobile app development technologies used by html5 developers across the globe. It is a new version language and considered as energetic challenger with latest characteristics and elements. It addresses web application needs with advanced technology and powerful elements.

The latest version language leverages its power in creating a unique and highly attractive website. As the demand increases, numerous developers are empowering their knowledge on HTML5 to create an excellent website for various business needs. This article enlightens you about the growing popularity of hybrid mobile app development

Let us see how it takes you on achievement of HTML5.

HTML5 provides world-class technology to hybrid mobile app development. It provides advanced technologies to develop robust hybrid app that satisfies various requirements of different application mobile market apps such as Play store and Google App. It is one of the best challengers and uses multi-talent skills to perform hybrid apps with high-end functionality. A recent survey states that, it is trusted by 80% app developers and entrepreneurs for building mobile apps with advanced performance.

Updating HTML5 dynamic apps remotely using cutting-edge functions

It plays a significant role in managing the app easily for users and a unique thing is the mobile app developed using the technology can be updated virtually via advance functions. Systematic updating is one of the best aspects integrated with HTML-based hybrid apps and ensures good support for various versions of the respective app.

Far-fetched triumph within inexpensive availability of HTML5

It plays a key role in mobile app development projects and delivers mobile apps within world-class quality at worthy prices. Integration of systematic updating in new web browsers is one of unique benefit about it. It provides advanced features and storage options with a great user experience. By using the app developers can perform best app development projects in a HTML5 development company.

System fonts can be conveniently used by users along with access of HTML5

As an app developer, you must able to predict the targeted users thought how they access your app. With help of the system fonts it possible to execute font stacks for developing apps. The functionality of appropriate system fonts can ensure outstanding performance for your app’s success, if you have planned to create an amazing mobile. It will be very helpful in creating apps for advanced mobile platforms.

Source Link: http://djdesignerlab.com/2015/07/23/why-is-html5-becoming-popular-as-a-hybrid-mobile-app-development-tool/

Formidable Reasons that Make HTML5 the Favorite of Web Developers Today



Beyond any comparison, the fifth as well as the latest version of Hyper Text Markup Language is absolutely fantastic in many terms. It has been addressed as a timely innovation which website builders eye to frame websites. All the advanced technologies essentially, Java, CSS, flash programs, and other APIs are brilliantly supplemented for manifesting website contents in the framework of HTML5, superior to XHTML. There are some sound, practical, and clear-cut reasons that add to the popularity of HTML5 in today’s website building scenario. An HTML5 developer gets more options to frame websites compared to programmers working with similar platforms. This extract explains how HTML5 becomes a valuable companion for website builders.

Smartphone compatibility

No doubt the world nowadays is after handheld and compatible screen resolutions. Mobile devices have taken over the communication needs of the world in all means; hence responsive designs stand inevitable to a designer. HTML5 is a ready-made tool to create sites and web applications for any kind of screen sizes. Meta tags of HTML5 are exclusively crafted for optimizing smaller screen displays. This framework offers immense choices to design widths, full screen modes, and home buttons so easily in all popular operating systems.

Elegant and neat codes

Objective codes that are more meaningful, simple and easy to split and describe are the lifeline of any modern framework. HTML5 is supreme in this aspect. No designer can call for a better code than HTML 5. Its <header>, <footer>, <article> so on are built-in to help the designers to arrange their CSS in an effective way. The web contents look simple, clean, graceful, and illustrative with HTML5.

Doctype attributes

Editing and pasting of long winding codes happen to be a nightmare for most designers. Doctype attributes readily available with HTML5 set it as an easy task for designers. The beauty of these doctype attributes is that it goes with most of the web browsers.

Interactive/ dynamic

A lively website should be dynamic. It must respond to the activities of users correctly. Users receive a much improved experience with APIs and animations while working with HTML5. Media playbacks along with animations work well in HTML5, for it has advanced CSS functionalities to the core.

Multiple browser support


The codes are modern, so some of the older versions of IE6 fail to support it. Still all the browsers including Firefox, Opera, and chrome so on are perfect for HTML5. Expert developers can even use the codes in IE6 as well, by making some small changes in the java codes.

Storage space& Location support

The local storage feature is one of the best features of this platform. The data used by the user will remain in storage spaces, even if the user deletes all cookies. Creating of apps can be made simple with HTML5 by using this function. Recent additions like GPS locations enable HTML5 to provide valid information to the user based on the user’s geo-location itself.

Great support for audio & video

Inclusion of audio or video in web contents is a real task for designers. They will have to include a large set of codes to accomplish the task. HTML5 has reduced this task to mere 50%. It enables all media files both audio and video, play well having less weighted codes attached to it. The result is fast downloading of files, and super speed browsing.

Handy semantics

Screen readers can easily analyze the classes defined with HTML5. Thus navigating with HTML documents happens to be pretty simple for screen readers resulting in a great user experience.

Conclusion

Rightly, HTML5 is a technology meant for the future. Let it be the creation of animated videos, mobile applications, games, and other features for a website, HTML5 stands as an inescapable technology. Get it and stay up- to- date.

How to improve Mobile Web Application Development when using HTML5

HTML5 is increasingly being used in the mobile web application development as it has many advantages to it, such as ease of maintenance, interoperability and sooner development time. This markup language, along with JavaScript and CSS, forms the core technology for every developer. HTML5 has APIs and a set of standards which are supported by all the major browsers. Also, several of the HTML5 APIs like localstorage are supported by many browsers.



In the past few years, with the emergence of tablets and smartphones, the number of people using websites on desktops has witnessed a reduction. Most people, these days, access websites on their mobile devices or straightaway download the app. Though apps have been gaining momentum, the use of mobile websites is here to stay, because, they are instantly available, are compatible across devices, are easily upgradable, easily shareable by users via a link and involve lesser cost and time in development, and so on.

It is exactly for all these reasons does the need for HTML5 in developing mobile websites comes into picture. Here, in this article, let us get a glimpse of methods through which mobile web application development using HTML5 can be improved.

Improve Mobile web app development using HTML5

An impeccable website, which can be used on mobile browsers, can be developed with ease by considering some of the aspects. Mainly, an Html5 developer has to bear in mind the screen size and resolution of the mobile device; the actual content the mobile users need, and if their HTML, CSS and JavaScript are valid and compact.

Keeping in mind the perspective of the users, the mobile site has to be designed, and important content has to be provided. Having said that, not all the content available on the desktop site needs to be part of the mobile website. It is more likely that users will quit the site, in case, they do not get their necessary information at the very first glance, for the simple reason that they do want to get into each page of your website.

More importantly, ensure that you test your site on various mobile devices. Check if the images are loading; if it is possible to scroll horizontally; if all the features are working or not, and if the file formats are being supported or not. A comprehensive checking is required to ensure that the mobile website developed using HTML5 is picture perfect.

Things to avoid while developing web pages for mobile devices

  • Due to the smaller size of the mobile screen, do not use tables, as much as possible, in mobile layouts so that the website users do not have to scroll it much.
  • Ensure that you do not add invisible graphics to add spaces. If in case the graphics are added, the download time may increase, and the pages may be displayed incorrectly.
  • Popup windows are not appreciated by many mobile website users. They are not only annoying, but also render the site unusable. So, ensure that you take the necessary measures.


An HTML5 developer has to take steps to ensure the websites' mobile browser compatibility. Also, every HTML5 development company should develop and improvise mobile web applications to make them user-friendly for individuals who access them.

Create PDF invoices with HTML5 and PhantomJS

Creating invoices in PDF is always a bit tricky: there are many libraries to create PDF documents with PHP, but most can't handle complex layouts and require a lot of memory and CPU time. Things like Unicode characters and line/page breaks are often difficult to program and the source of many bugs and memory problems. Using logos as vector graphics or embedding TrueType fonts is often required, but not possible with most libraries.

The good thing is that all these features are included in HTML5. Since most companies offer their invoices also in HTML, it would be great to convert them directly to PDF. Tools like html2ps and ps2pdf can produce PDFs with 200+ pages without problems, but only support HTML4 and some very limited CSS. Also, the layout is never the same as in a web browser.

So we need a real web browser to convert HTML pages to PDFs. From testing web applications, we know that PhantomJS is a headless WebKit browser that runs on the commandline and can automate things very easily. The great thing is that it can also create screenshots and PDFs with selectable texts and embedded fonts! So we can use all kinds of CSS (Truetype fonts, round borders, etc.), SVG images, DIVs and tables to create great looking invoices.

Here is a PhantomJS script that converts an HTML file into a PDF:


// html2pdf.js
var page = new WebPage();
var system = require("system");
// change the paper size to letter, add some borders
// add a footer callback showing page numbers
page.paperSize = {
format: "Letter",
orientation: "portrait",
margin: {left:"2.5cm", right:"2.5cm", top:"1cm", bottom:"1cm"},
footer: {
height: "0.9cm",
contents: phantom.callback(function(pageNum, numPages) {
return "<div style='text-align:center;'><small>" + pageNum +
" / " + numPages + "</small></div>";
})
}
};
page.zoomFactor = 1.5;
// assume the file is local, so we don't handle status errors
page.open(system.args[1], function (status) {
// export to target (can be PNG, JPG or PDF!)
page.render(system.args[2]);
phantom.exit();
});

Let's start the conversion:


time phantomjs html2pdf.js invoice.html invoice.pdf
real 0m0.189s
user 0m0.096s
sys 0m0.020s

time html2ps invoice.html | ps2pdf - invoice.pdf
...
real 0m3.521s
user 0m0.656s
sys 0m0.208s
(phantomjs 1.6.1, html2ps 1.0b7, 3.4 GHz single core, QEMU)

Here is the example invoice.html containing a SVG logo, tables, a TrueType font and CSS styles:

And it gets a perfect PDF with 2 pages in less than 1 second:

The size of the PDF is 65 KB. Using LibreOffice for the conversion gives 130 KB, html2ps produces 8 KB without the logo and the fonts.

The source files and the target PDF can be downloaded here.

Note: manual page breaks can be added with:

<div style="page-break-before:always;"></div>
or
<div style="page-break-after:always;"></div>

Note: Support for the WebOpenFontFormat (woff) will be available in future releases, so currently only TrueType fonts are supported.

How to implement a real-time chat server in PHP using Server-Sent Events (update: added C benchmark)

Lessons learned:
  • A web server written in PHP can give more than 10000 req/s on small hardware
  • A web server written in PHP is not slower than being written in Java (without threads)
  • A web server written in PHP is 30 percent slower than being written in C (without threads)
  • Realtime applications can be developed in PHP without problems

PHP normally runs inside a web server like Apache or nginx. This keeps all requests separate from each other and does not allow sharing memory or connections. To implement a chat server, the browser has to poll the server regularly for new data. The data is stored in a database and looked up for each request. This is very slow, takes a lot of resources on the server and does not give messages in realtime.
Newer browsers support data being pushed from the server to the client. There are two techniques used: WebSockets (full-duplex) and Server-Sent Events (push notifications)
Using these techniques, one connection stays open for each client and the server sends (pushes) messages whenever new data is available. To handle many connections – that stay open for a long time – and share messages between these connections, we run PHP as a standalone process on the shell and implement a web server directly in PHP.
In the browser, we use Server-Sent Events to receive messages in realtime and AJAX requests to send new messages. We allow more than one connection (=browser tab) per user. We allow sending messages to all users or one specific user. If the user is offline, the message will be kept in memory for later delivery.

Here is the code:

// Usage: run "php server.php" and open a few browser tabs with "http://<ip>:8000/".

// server.php #1 html page
$html = "<html>
<body>
<script>
var inactive = 0;
// show 'username (x)' in document title when there are
// new messages and the tab is not visible
window.onfocus = function(){
inactive = 0;
document.title = document.forms[0].nick.value;
};
window.onblur = function(){ inactive = 1; };
var html = function(s){ return s.replace(/>/g,'>').replace(/</g,'<'); };
</script>

<!-- nickname form, start receiving messages on submit -->
<form onsubmit=\"
var source = new EventSource('/'+this.nick.value);
source.onmessage = function(event){
document.getElementById('content').innerHTML += html(event.data)+'<br>';
if (inactive) document.title = document.forms[0].nick.value+' ('+(inactive++)+')';
};
this.style.display = 'none';
document.forms[1].style.display = '';
document.forms[1].msg.focus();
document.title = this.nick.value;
return false;
\">
<input type='text' name='nick' required='true' autofocus='true' />
<input type='submit' value='Choose nickname'/>
</form>

<!-- message form, send new message as ajax request -->
<form onsubmit=\"
var ajax = new XMLHttpRequest();
ajax.open('GET', 'http://localhost:8000/msg/' + escape(document.forms[0].nick.value) +
'/'+escape(this.msg.value));
ajax.send();
this.msg.value = this.msg.value.substr(0, this.msg.value.indexOf(' ')+1);
this.msg.focus();
return false;
\" style='display:none;'>
<input type='text' name='msg' required='true' placeholder='nickname message' style='width:250px;' />
<input type='submit' value='Send message' />
<input type='button' value='Clear chat' onclick=\"document.getElementById('content').innerHTML='';\" />
</form>

<div id='content'><!-- chat messages --></div>
</body>";

// server.php #2 socket server (port 8000)
$socket = stream_socket_server("tcp://0.0.0.0:8000", $errno, $err) or die($err);
$conns = array($socket);
$conn_ids = array(0);
$conn_user = array();
$msgs = array();

// server loop
while (true) {
$reads = $conns;
// get number of connections with new data
$mod = stream_select($reads, $write, $except, 5);
if ($mod===false) break;

foreach ($reads as $read) {
if ($read===$socket) {
$conn = stream_socket_accept($socket);
$recv = fread($conn, 1024);
if (empty($recv)) continue;

if (strpos($recv, "GET / ")===0) {
// serve static html page from memory
fwrite($conn, "HTTP/1.1 200 OK\r\n". "Connection: close\r\n".
"Content-Type: text/html; charset=UTF-8\r\n\r\n");
fwrite($conn, $html);
stream_socket_shutdown($conn, STREAM_SHUT_RDWR);

} else if (strpos($recv, "GET /msg/")===0) {
// ajax request: send a message
// syntax: GET /msg/user_from/user_to%20message
// e.g. GET /msg/john/mary%20hello
stream_socket_shutdown($conn, STREAM_SHUT_RDWR);
preg_match("!GET /msg/([^/]+)/(\S+)!", $recv, $match);
$user = $match[1];
$match[2] = urldecode($match[2]);
if (!strpos($match[2], " ")) continue;
list($target, $msg) = explode(" ", $match[2], 2);

if ($target=="all") {
// send message to all users
foreach ($conns as $i=>$conn) {
if ($i!=0) fwrite($conn, "data: ".$user." to all: ".$msg."\n\n");
}

} else if (isset($conn_user[$target])) {
// send message to one user and to the originator
if ($target!=$user) foreach ($conn_user[$target] as $conn) {
fwrite($conn, "data: ".$user.": ".$msg."\n\n");
}
if (isset($conn_user[$user])) foreach ($conn_user[$user] as $conn) {
fwrite($conn, "data: You to ".$target.": ".$msg."\n\n");
}

} else {
// user is offline, keep message in memory for later delivery
if (!isset($msgs[$target])) $msgs[$target] = "";
$msgs[$target] .= "data: ".$user." (".@date("Y-m-d H:i")."): ".$msg."\n\n";
foreach ($conn_user[$user] as $conn) {
fwrite($conn, "data: You to ".$target." (offline): ".$msg."\n\n");
}
}

} else if (strpos($recv, "text/event-stream")===false) {
// block other requests like favicon.ico
stream_socket_shutdown($conn, STREAM_SHUT_RDWR);

} else {
// login as new user
// syntax: GET /username e.g. GET /john
preg_match("!GET /(\S+)!", $recv, $match);
if (!isset($match[1])) continue;
$user = $match[1];
echo "connect ".$user." from ".stream_socket_get_name($conn, true)."\n";

fwrite($conn, "HTTP/1.1 200 OK\r\n". "Connection: close\r\n".
"Content-Type: text/event-stream\r\n\r\n");
fwrite($conn, "data: Welcome ".$user."!\n\n");
fwrite($conn, "data: now online: ".implode(", ", array_keys($conn_user))."\n\n");

// deliver messages sent when user was offline
if (isset($msgs[$user])) {
fwrite($conn, $msgs[$user]);
unset($msgs[$user]);
}
// notify other users
foreach ($conns as $i=>$c) {
if ($i!=0) fwrite($c, "data: ".$user." has joined.\n\n");
}
// register connection in pool
$conns[] = $conn;
$conn_ids[] = $user;
// allow multiple connections for 1 user
$conn_user[$user][] = $conn;
}
} else {
$data = fread($read, 1024);
if ($data=="" or $data===false) {
// user/browser closed connection
if ($data!==false) stream_socket_shutdown($read, STREAM_SHUT_RDWR);
$conn_id = array_search($read, $conns, true);
unset($conns[$conn_id]);

// unregister connection for user
$user = $conn_ids[$conn_id];
unset($conn_ids[$conn_id]);
$conn_id = array_search($read, $conn_user[$user], true);
unset($conn_user[$user][$conn_id]);

if (empty($conn_user[$user])) {
unset($conn_user[$user]);
// notify other users
foreach ($conns as $i=>$c) {
if ($i!=0) fwrite($c, "data: ".$user." has left.\n\n");
} } } } } }
Please note that this implementation does not cover user authentication or saving messages to disk or database. Also, connection errors or timeouts are not handled on the browser side.
This code is just for demonstration of the concepts and the performance, so it is not OOP and it should not be used in production. Also it does not implement a complete HTTP stack or handle mime types.

To test the performance of our chat server, let's do some "GET / HTTP/1.1" and serve the static HTML output. ab works good here because it covers all possible scenarios.

php server.php (PHP 5.3.10, 3.4 GHz single core QEMU, VQ7 from Hetzner)

# serve static content
ab -n 10000 -c 10 http://localhost:8000/
Requests per second: 11601.30 [#/sec] (mean)
(memory usage is about 12.5M)

# receive messages (1st shell)
curl -sH ": text/event-stream" http://localhost:8000/john >/dev/null
# send messages (2nd shell)
ab -n 10000 -c 10 http://localhost:8000/msg/mary/john%20hello
Requests per second: 9872.04 [#/sec] (mean)

javac Server.java && java Server (IcedTea7 2.3.3, 1.7.0_09)

ab -n 10000 -c 10 http://localhost:8000/
Requests per second: 10440.45 [#/sec] (mean)

// Server.java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Server {
private static String readFile(String pathname) throws IOException {
File file = new File(pathname);
StringBuilder fileContents = new StringBuilder((int) file.length());
Scanner scanner = new Scanner(file);
try {
while (scanner.hasNextLine())
fileContents.append(scanner.nextLine() + "\n");
return fileContents.toString();
} finally {
scanner.close();
}
}

public static void main(String[] args) throws Exception {
final String html = readFile("test.html");
try (ServerSocket socket = new ServerSocket(8000)) {
while (true) {
final Socket client = socket.accept();
try (Socket c = client) {
while (true) {
DataInputStream dis = new DataInputStream(c.getInputStream());
DataOutputStream dos = new DataOutputStream(c.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(dis));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(dos));
String recv = in.readLine();
if (recv != null && recv.indexOf("GET / ") == 0)
out.write("HTTP/1.1 200 OK\r\nConnection: close\r\n"
+ "Content-Type: text/html; charset=UTF-8\r\n\r\n" + html);
// using StringBuilder was slower ...
out.close();
in.close();
}
} catch (IOException e) {
// ok
}
}
} catch (IOException e) {
System.out.println(e);
} } }

gcc -o server.bin server.c && ./server.bin (gcc 4.6.3)

ab -n 10000 -c 10 http://localhost:8000/
Requests per second: 15254.44 [#/sec] (mean)
(memory usage is about 0.5M)

// server.c
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main() {
int server, instance;
socklen_t clilen;
char buffer[256];
struct sockaddr_in srv, cli;
char html[] = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html;\
charset=UTF-8\r\n\r\n\
<html>\
<body>\
<script>\
var inactive = 0;\
...
</body>";
int html_len = strlen(html);

server = socket(AF_INET, SOCK_STREAM, 0);
bzero((char *) &srv, sizeof(srv));
srv.sin_family = AF_INET;
srv.sin_addr.s_addr = INADDR_ANY;
srv.sin_port = htons(8000);
int opt = 1;
setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
if (bind(server, (struct sockaddr *) &srv, sizeof(srv)) < 0) {
perror("ERROR: bind");
exit(1);
}
listen(server,5);
clilen = sizeof(cli);
do {
instance = accept(server, (struct sockaddr *) &cli, &clilen);
if (instance < 0) continue;
bzero(buffer,256);
read(instance,buffer,256);
if (strstr(buffer, "GET / ")) write(instance, html, html_len);
close(instance);
} while(1);
return 0;
}

Apache (v2.2.22, from disk with logging enabled)

ab -n 10000 -c 10 http://localhost/public/test.html
Requests per second: 6491.84 [#/sec] (mean)

node test.js (node.js v0.6.12)

ab -n 10000 -c 10 http://localhost:8000/
Requests per second: 5554.03 [#/sec] (mean)

// test.js
var str = "<html>\
<body>\
<script>\
var inactive = 0;\
...
</body>";
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(str);
}).listen(8000, '127.0.0.1');
node test2.js (node.js v0.6.12)

ab -n 10000 -c 10 http://localhost:8000/
Requests per second: 9075.90 [#/sec] (mean)

// test2.js
var str = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n\
<html>\
<body>\
<script>\
var inactive = 0;\
...
</body>";
var net = require('net');
var server = net.createServer();
server.listen(8000, '127.0.0.1');
server.on('connection', function(sock) {
sock.end(str);
});