Some conclusions on developing mobile websites

Some conclusions on developing mobile websites

The mobile version of the website should at least have some basic functions:

1. Page applicability issues:

Mobile terminals have different resolutions and screen sizes. If you still limit the width of the web page to 1003px or other pixel values ​​like the computer design, and use 12px or 14px for the font size, then the effects of different terminals will be very different. So here, it is best to make the width of the web page adaptive to the screen. Fortunately, W3C considered this for us when designing HTML. It can be done in just one sentence, that is, add


Copy code
The code is as follows:

<meta name="viewport" content="width=device-width"/>

For fonts, we can just use em or ex as the unit.

2. Version production issues:

Mobile pages often have different versions for different mobile phones, generally including simplified version, standard version, 3G version, touch screen version, smart phone version, etc. In addition to the differences in page design, the page language will also be different. The simplified version is written in wap 1.0 wml script, which is very versatile and many domestic mobile phones support this language, but this language is very simplified. The standard version generally uses WAP 2.0 technology, and the corresponding scripting language is XHTML MP (XHTML Mobile Profile). This language is a subset of XHTML, and supports most CSS. It is basically the same as the computer version, but JS cannot be used generally. This is because these mobile phones do not support JS. As for the smartphone version, since all current smartphones support js, the production of this version is much simpler. However, since most smartphones (basically excluding Symbian phones, including Android, ios, wp7, etc.) support Html5, the smartphone version can be produced using html5.

3. Version control issues:

This part may be difficult to solve. How to intelligently determine the best version of the mobile phone and jump to it can be considered from the following aspects. On the one hand, you can find a way to get the operating system of the mobile phone, for example, if it is Android or iOS, you can jump to the HTML5 version. For the Windows system, there is no doubt that the computer version can get the mobile phone system by getting the phone model. The current method is through the browser's UA (user agent) to get some information about the phone. A simpler way is to directly determine the manufacturer of the phone through the UA. To obtain more information, you need a database, because different mobile phone models will have different UA information. There are many mobile phones in the world, and it is still difficult to make such a database by yourself. However, someone has already made such a database for us, or more conveniently, made a function library to identify the best version for the mobile phone. Here I recommend using Wurfl. On the other hand, you can use the script on the page to determine whether the browser supports js and html5. The code is as follows


Copy code
The code is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width"/>
<title>Version Control</title>
<script type="text/javascript">
window.onload = function(){
// Check if js is supported
try{//Check whether HTML5 is supported
document.getElementById("c").getContext("2d");
document.location = 'Links that support HTML5';
}catch(e){//Otherwise jump to the js version
document.location = 'Support js version';
}
};
</script>
</head>
<body>
<canvas id='c'></canvas>
Regular Edition
</body>
</html>

If you just want to develop a version, just to determine whether it is a mobile client, here is a code quote from discuz! x2


Copy code
The code is as follows:

<?php
function checkmobile() {
global $_G;
$mobile = array();
static $mobilebrowser_list = array('iphone', 'android', 'phone', 'mobile', 'wap', 'netfront', 'java', 'opera mobi', 'opera mini',
'ucweb', 'windows ce', 'symbian', 'series', 'webos', 'sony', 'blackberry', 'dopod', 'nokia', 'samsung',
'palmsource', 'xda', 'pieplus', 'meizu', 'midp', 'cldc', 'motorola', 'foma', 'docomo', 'up.browser',
'up.link', 'blazer', 'helio', 'hosin', 'huawei', 'novarra', 'coolpad', 'webos', 'techfaith', 'palmsource',
'alcatel', 'amoi', 'ktouch', 'nexian', 'ericsson', 'philips', 'sagem', 'wellcom', 'bunjalloo', 'maui', 'smartphone',
'iemobile', 'spice', 'bird', 'zte-', 'longcos', 'pantech', 'gionee', 'portalmmm', 'jig browser', 'hiptop',
'benq', 'haier', '^lct', '320x320', '240x320', '176x220');
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(($v = dstrpos($useragent, $mobilebrowser_list, true))) {
$_G['mobile'] = $v;
return true;
}
$brower = array('mozilla', 'chrome', 'safari', 'opera', 'm3gate', 'winwap', 'openwave', 'myop');
if(dstrpos($useragent, $brower)) return false;
$_G['mobile'] = 'unknown';
if($_GET['mobile'] === 'yes') {
return true;
} else {
return false;
}
}
function dstrpos($string, &$arr, $returnvalue = false) {
if(emptyempty($string)) return false;
foreach((array)$arr as $v) {
if(strpos($string, $v) !== false) {
$return = $returnvalue ? $v : true;
return $return;
}
}
return false;
}
var_dump(checkmobile()); //If it is a mobile terminal, return true, otherwise false
?>

4. Size issue of mobile version:

Generally speaking, for the simplified and regular versions of mobile web pages, we try to make them as concise as possible, and it is best to save as much code as possible. After all, mobile data traffic is still very precious to users. For example, when naming elements, if there are few pages, the shorter the name, the better, and the CSS is best written in one line. In CSS, some elements inherit the style of their parent class. There is no need to define them repeatedly, and make good use of the default values.

5. Browser Cache:

If the update is not fast, it is best to enable browser cache.

<<:  Implementation steps for installing RocketMQ in docker

>>:  How to prevent Flash from covering HTML div elements

Recommend

A brief analysis of MySQL's lru linked list

1. Briefly describe the traditional LRU linked li...

Background gradient animation effect made by css3

Achieve results Implementation Code html <h1 c...

MySQL 8.0.17 installation and configuration method graphic tutorial

This article shares the installation and configur...

MySQL partitions existing tables in the data table

Table of contents How to operate Operation proces...

CocosCreator ScrollView optimization series: frame loading

Table of contents 1. Introduction 2. Analysis of ...

A super detailed Vue-Router step-by-step tutorial

Table of contents 1. router-view 2. router-link 3...

JavaScript modularity explained

Table of contents Preface: 1. Concept 2. The bene...

Docker installs the official Redis image and enables password authentication

Reference: Docker official redis documentation 1....

Detailed explanation of Docker container data volumes

What is Let’s first look at the concept of Docker...

Modify the jvm encoding problem when Tomcat is running

question: Recently, garbled data appeared when de...

mysql 8.0.19 win10 quick installation tutorial

This tutorial shares the installation tutorial of...