New requirements for the project, Adaptive Delivery/responsive delivery of Web pages responsive/adaptive Delivery

Source: Internet
Author: User
Tags setcookie

Why the Web page to do adaptive delivery, all because the mobile device is now a big line, is now the mobile internet era, with iOS and Android-led mobile terminal has been everywhere.

When people use the 380px iphone to open your Web page, you can not display a 1024px page to others, the user experience big discount purchase, because responsive design or adaptive delivery came into being.

The responsive design has been mentioned before, but the focus of the responsive design is that no matter what the 3721, all resources (HTML,CSS,JS) are loaded down, the pages are responsive, and responsive delivery is the perfect response . is the server and according to the visitor's device terminal, the dynamic delivery of the corresponding HTML, CSS, JS resources, all is a real thing, no redundant code or resources. It is said that ASP. NET MVC 4 can easily implement this function, of course, Dynamic Response.Write Server can also dynamically spell the page, but the workload is big AH! The back end of the family refused to ...

Helpless, the project is urgent, to persuade PM to use the current more popular pseudo-responsive delivery method, with page redirection (redirect) and page cookie control combined

Demand:

First, the design of 2 sets of templates, one is a tablet/desktop-side template (www.yoursite.com), the other is the mobile phone (www.yoursite.com/mobile as a sub-station) template

Ii. Responsive Delivery

Add the following JS code at the top of the full site page

varUserAgent =window.navigator.userAgent.toLowerCase ();varCurrenturl =window.location.href.toLowerCase (); varTargetSite = GetCookie (' TargetSite '));if(TargetSite = = "| | targetsite = =NULL|| TargetSite = = ' Mobile '){    if(Useragent.indexof (' ipad ') = =-1 && useragent.indexof (' mobile ')! =-1)    {        {            varNewurl = Currenturl.tolowercase (). Replace (' www.yoursite.com ', ' www.yoursite.com/mobile '); Setcookie (' TargetSite ', ' mobile ', '/'); if(Currenturl.indexof ('/mobile/') = =-1) {window.location.href=Newurl; }         }           }}/*****cookies * * **/functionSetcookie (name, value, path) {varDate =NewDate (); Date.settime (Date.gettime ()+ 0.5 * 24 * 3600 * 1000);//Cookie lasts half of a day.    varp = ""; if(path) {p= ";p ath=" +path; } document.cookie= name + "=" + Escape (value) + "; expires=" + date.togmtstring () +p;}functionGetCookie (name) {vararr = Document.cookie.match (NewRegExp ("(^|)" + name + "= ([^;] *)(;|$)")); if(Arr! =NULL)        returnUnescape (arr[2]); return NULL;}functionDelcookie (name) {varExp =NewDate (); Exp.settime (Exp.gettime ()-1); varCval =GetCookie (name); if(Cval! =NULL) Document.cookie= name + "=" + Cval + "; expires=" +exp.togmtstring ();}

In mobile site, you have to choose to jump to full site link, which should be added to the cookie control

function Redirectfullurl () {    var currenturl = window.location.href.toLowerCase ();    Delcookie ("TargetSite");    Setcookieforsitetarget ("TargetSite", "full", "/");     var newurl = Currenturl.tolowercase (). Replace (' Www.yoursite.com/mobile ', ' www.yoursite.com ');     = Newurl;}

This is OK, the principle is relatively simple, mainly through the control of cookies to guide, of course, your full site and mobile Site page all corresponding to be strictly on the

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.