Results 1 to 4 of 4

Thread: Make Your Site Mobile-Friendly in Two Minutes

  1. #1
    Senior Member bOrN2pwn's Avatar
    Join Date
    Mar 2009
    Location
    Ellisras, Limpopo, South Africa, 106067582767544, Ellisras
    Posts
    230
    Thanks
    16
    Thanked 49 Times in 21 Posts
    Blog Entries
    1
    Rep Power
    5

    Talking Make Your Site Mobile-Friendly in Two Minutes

    After checking out B. Adam Howell's excellent IYHY.com site a couple of weeks ago, I thought it might be a good idea to write a little tutorial about how to make your entire site more mobile-friendly without even touching your pages. You may think that since you write valid code and separate structure from presentation at all times, your site already works great on mobile devices. You may also think bad things don’t happen to good people. In both cases, you'd be wrong.

    The fact of the matter is that the state of HTML rendering in the wireless world is all over the map right now. Some browsers, like Pocket Internet Explorer, are actually pretty good at parsing through standard web pages. Others can scarcely handle layout rules at all. And still worse are the mobile browsers that load all CSS and JavaScript files, attempt to use them, and screw up the experience even more in the process.

    What’s really needed until HTML/CSS/JS support is improved in mobile devices is a little server-side filtering. By pulling out everything a mobile device can possibly choke on before it even gets to the mobile device, we can create a mobile version of our site which is not only viewable on more devices but is much quicker to download as well.

    And you know what? The mobile version of your site is probably going to be much easier on screen-readers too.

    Four easy steps

    Outlined below are the four steps to get this done in a matter of minutes, provided you are in an Apache environment and can run PHP. If you’re not, these steps can easily be adaptable to other technologies.

    Step 1: Set up a domain mirror

    If your site lives at www.myawesomeblog.com, you’re going to want to set up a subdomain at mobile.myawesomeblog.com. How you accomplish this is usually pretty straightforward but differs depending on your host. I use amplehosting and from their control panel, I can add subdomains effortlessly until I pass out from excitement. You want to set up your subdomain as a “mirror” of your main site, meaning the subdomain is really just pointing to your existing site.

    Step 2: Create global_prepend file

    The next thing we’re going to do is a create a PHP file which will be automatically prepended to every page of our site. Call this file something like "global_prepend.php" and throw it at the root of your server:

    PHP Code:
    <br />
    <?php<br />
    function 
    callback($buffer) {<br />
        if (
    $_SERVER['SERVER_NAME'] == 'mobile.myawesomeblog.com') {<br />
            
    $buffer str_replace('http://www.myawesomeblog.com''http://mobile.myawesomeblog.com'$buffer);<br />
            
    $buffer preg_replace('/[\n\r\t]+/'''$buffer);<br />
            
    $buffer preg_replace('/\s{2,}/'' '$buffer);<br />
                
    $buffer preg_replace('/(<a[^>]*>)(<img[^>]+alt=")([^"]*)("[^>]*>)(<\/a>)/i''$1$3$5<br />'$buffer);<br />
            
    $buffer preg_replace('/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|<img[^>]*>|style="[^"]*")|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!--.*?-->/i'''$buffer);<br />
            
    $buffer preg_replace('/<\/head>/i''<meta name="robots" content="noindex, nofollow"></head>'$buffer);<br />
        }<
    br />
        return 
    $buffer;<br />
    }<
    br />
    ob_start("callback");<br />
    ?>
    This code uses a PHP function called ob_start() to read in your entire HTML source, run some rules on it, and then send the output to users’ web browsers… all in real time. The first "if" statement simply checks to see if the user is coming from our special “mobile” URL, and if so, runs seven replace statements on the code. Here’s what each line does:
    1. Changes all URLs to “mobile”-ized URLs.
    2. Strips all linefeeds, carriage returns, and tabs.
    3. Trims multiple spaces down to one (HTML doesn’t recognize more than one space in a row).
    4. Changes any anchored images with alt text to plain text anchors.
    5. Strips all stylesheets, images, inline styles, scripts, and comments (including RDF).
    6. Tells search engine robots not to index or crawl the mobile version of the site so as to not create duplicate listings.


    Step 3: Create global_append file

    Next, we need to create a tiny PHP file which will automatically get added to the end of every file on our site. This is the code that actually outputs the page to the browser. So the flow is like so: Suck code into buffer, siphon fat away, spit contents of buffer into browser.

    The code for the global_append file is below. Call it something like "global_append.php" and throw it at the root of your server:

    PHP Code:
    <br />
    <?php<br />
        
    ob_end_flush();<br />
    ?>
    Step 4: Enable prepends and appends using .htaccess

    If you don’t already have an .htaccess file at the root of your server, open up a new text file and add these lines to it:

    php_value auto_prepend_file /localfilepath/global_prepend.php
    php_value auto_append_file /localfilepath/global_append.php


    Then save it to the root of your server with the filename ".htaccess". If you already have an .htaccess file, just add the above lines to it.

    * Important Note: If you copy these two lines from your web browser, you might need to delete the carriage return and make your own. Sometimes a browser’s carriage return will cause your .htaccess file to fail (you’ll know immediately if it has failed because your site won’t come up).

    Assuming your subdomain is live, you should now be able to hit your site in a web browser using the special mobile URL and see a nice, compact, imageless, styleless, scriptless version of your site. Voila!

    Last edited by bOrN2pwn; 01-01-10 at 18:14.
    BakGat
    Code:
    class Counter {
    public:
      void Count();
      int  ReadDisplay();
    private:
      int  CurrentCount;
    };








    Back up my hard drive? How do I put it in reverse?
    [Only registered and activated users can see links. Click Here To Register...]
    My Community
    [Only registered and activated users can see links. Click Here To Register...]
    WapLive Hosting Cpanel11

  2. The Following 3 Users Say Thank You to bOrN2pwn For This Useful Post:

    lahirukk (17-01-10), Mysterio3 (29-07-10), sachin007 (15-08-10)

  3. #2
    Moderator riderz's Avatar
    Join Date
    Mar 2009
    Location
    EMalahleni, South Africa
    Posts
    1,350
    Thanks
    108
    Thanked 391 Times in 128 Posts
    Rep Power
    6

    Default

    nice tutorial m8 tanx
    ________________
    Jacques
    [Only registered and activated users can see links. Click Here To Register...]
    [Only registered and activated users can see links. Click Here To Register...]
    [Only registered and activated users can see links. Click Here To Register...]
    __________________

    NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH

  4. #3
    Senior Member
    Join Date
    Mar 2009
    Location
    Albania, East Europe
    Posts
    618
    Thanks
    180
    Thanked 54 Times in 27 Posts
    Rep Power
    5

    Default

    thanks for this tutorial brother!

  5. #4
    Member pakalika's Avatar
    Join Date
    Mar 2008
    Location
    Brasil
    Posts
    67
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Nice tutorial. Thanks dude!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Phn.me A New Mobile Site Creator
    By asidana in forum Sites / Links
    Replies: 1
    Last Post: 10-02-09, 22:37
  2. Dotworldnet Mobile Site
    By CybeRAssassiN in forum Sites / Links
    Replies: 1
    Last Post: 22-12-08, 09:25
  3. Make Money Frm Ur Site
    By djmal in forum Domains - Hosting - Servers
    Replies: 2
    Last Post: 29-12-07, 01:35
  4. Learn Php In 10 Minutes
    By wapkralj in forum Tutorials
    Replies: 6
    Last Post: 14-07-06, 10:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19