programming4us
programming4us
MOBILE

Programming the Mobile Web : Content Delivery (part 1) - Defining MIME Types

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
A common situation in the mobile web world is content delivery. Java applications, widgets, music, video, wallpapers, and any other content can be delivered to compatible devices, but this requires a bit of explanation and expertise.

1. Defining MIME Types

MIME types, are a key element for content delivery. Many mobile browsers don’t care about the file extension; they decide whether or not to accept the content based on the MIME type delivered by the server. Remember that the MIME type travels with the HTTP header response.

1.1. Static definition

The simplest way to define the right MIME types is to statically define them on your web server. If you are working with a shared hosting service, the control panels often allow you to define document MIME types. If you manage your own server, you can set them up with the following instructions.

1.1.1. Apache

In Apache, the simplest way is to open the mime.types file located in the conf folder of the Apache root. In your favorite text editor, you can add one row per MIME type to be configured.

You will find hundreds of MIME type declarations. The first thing to do is to look for the following line and change the MIME type to the correct one for mobile XHTML documents:

text/html                    html htm

As you can see, each line contains a MIME type followed by a series of spaces or tabs and a space-separated list of file extensions.


Warning:

This technique applies these changes to all the websites on the server. If you want to make changes to only one website or one folder of a website, you should create or edit the .htaccess file in the appropriate folder and use the AddType procedure:

AddType   text/x-vcard   vcf


You can find an Apache configuration file to download and use with all the important mobile web MIME types at http://www.mobilexweb.com/go/mime.

1.1.2. Internet Information Server

Configuring MIME types in Microsoft IIS can be done via the UI (as opposed to in Apache, where you need to edit a text file). To configure the MIME types in IIS 6.0 on Windows XP or Windows Server 2003:

  1. Go to IIS Manager.

  2. Right-click the whole server, a website, or a folder and select Properties.

  3. On the HTTP Headers tab, click MIME Types.

  4. Click New, type the file extension and MIME type, and press OK to finish.

In IIS 7.0 for Windows Vista/7 and Windows 2008 Server:

  1. Go to IIS Manager.

  2. Navigate to the level you want to manage.

  3. In Features View, double-click on MIME Types.

  4. In the Actions pane, click Add.

  5. Type the file extension and MIME type and press OK to finish.


Note:

In IIS, you can also manage MIME types from the command line. Check the documentation for more information.


In IIS 7.0, it is also possible to define static MIME type declarations in the web.config file in your ASP.NET folder. The syntax is:

<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".vcf" mimeType="text/x-vcard" />
</staticContent>
</system.webServer>
</configuration

1.2. Dynamic definition

The other possible way to declare MIME types is to use dynamic header declarations in your server script code.

In PHP, you should define the MIME type before any other output using the header function:

header('Content-Type: application/xhtml+xml');

If you are delivering downloadable content (not markup), like a video, you should also define a filename. If not, when the file is saved it will have a .php extension and it will not work.


Note:

Remember that it is better to serve XHTML MIME types to mobile websites. You can define them either statically or, if you are using a server-side language, dynamically. You can also query WURFL or another library to check what the preferred MIME type to deliver is and use it to define the header.


To define the name of the file we use the Content-disposition header, as shown in the following sample:

$path = '/videos/video.mp4';
header('Content-Type: video/mp4');
header('Content-disposition: attachment; filename=video.mp4');
// We serve the file from our local filesystem
header("Content-Length: " . filesize($path) );
readfile($path);

ASP.NET has a Response.ContentType property that we can define:

// This is C# code
Response.ContentType = "application/xhtml+xml";

The filename should also be defined if it is downloadable content, using Response.AddHeader.

In a Java servlet or JSP, you should define the headers using the setContentType method of the response object:

response.setContentType("application/xhtml+xml");


Note:

When you are serving non-markup content using a dynamic script, if an error occurs you will not see the error details and the content will be broken (imagine a JPEG with a PHP error as the contents). You should capture any error, send yourself an email or log the error details, and replace the output with generic content.
Other  
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 3)
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 2)
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 1)
  •  iPhone Application Development : Using Advanced Interface Objects and Views - User Input and Output
  •  Windows Phone 7 Development : Wiring Up Events to an Application Bar ( part 2)
  •  Windows Phone 7 Development : Wiring Up Events to an Application Bar ( part 1) - Reacting to Add Button Events
  •  Adding an Application Bar to a Windows Phone 7 Application (part 3) - Adding an Application Bar Using Managed Code
  •  Adding an Application Bar to a Windows Phone 7 Application (part 2) - Adding a Local Application Bar Using XAML & Adding Menu Items
  •  Adding an Application Bar to a Windows Phone 7 Application (part 1) - Adding Images for Use with Application Bar Buttons & Adding a Global Application Bar Using XAML
  •  iPhone Application Development : Creating and Managing Image Animations and Sliders (part 3) - Finishing the Interface
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us