If you are reading this article, then you are most probably looking to speed up your website's page
load speed by distributing the images on a CDN (Content Delivery Network).
I was also looking to achieve the same for my blog am22tech.com and
found Google App. Engine as the best option.
The other option that you would find people talking about on internet is DropBox.com. I also evaluated DropBox but decided in favor of
Google App. engine for 1 major reason i.e. Google is NOT blocked on corporate office networks whereas
DropBox is!!
This essentially means that if you are hosting your images on dropBox and using it as CDN, anybody
accessing your site from a firewalled office network would not be able to see them. This is true for
any other type of files too i.e. CSS and javascript files.
Using Google App. Engine As Image CDN
There are couple of points that you need to understand before setting up Google App. Engine as CDN.
- You need a Google ID for using Google App Engine. If you use Gmail or any other Google service, you already have
it. Else register and i bet you will never regret joining Google network.
- By default, application on Google App. Engine uses a default URL in the form of
YOUR_APP_ID.appspot.com
The green text is what you will decide for your application. Red text is fixed. I registered my app.
with name am22images.
A more meaningful URL like
img.YOURSITE.COM
or anything else to represent your
custom domain. We will talk about this feature later in the article.
This essentially means that Google allows you to use a sub-domain or a custom domain of your main site
for using its infrastructure as a CDN.
I will use img.am22tech.com and show you how to map
am22images.appspot.com to img.am22tech.com.
Lets start with the process of using Google App. Engine as a CDN for storing and delivering images for
your website.
Set Up Google App. Engine As CDN with Eclipse
- Download and Install
Google App. Engine SDK. Don't worry, you don't need to do any coding. But you would need it for
creating a simple App. and deploy(copy) your images.
Use the "Google App Engine SDK for Java" and "Download the Google Plugin for Eclipse" options for
downloading the packages, unpack and install.
OR If you already have Eclipse on your machine, you can simply follow the instructions here to set up everything
in one click (I did this as it is a simple and recommended option).
- Go to Google App. Engine and log
in with your Google ID. Create a new application with a unique name. Give it any name. If you want to
use a custom domain/sub-domain for this application, you can map it later.
- Open Eclipse and create a web application.
File->New project->'Web Application Project'.
Enter any name for the 'project' and 'package'. Deselect 'Use Google Web Toolit' option. Leave all
other options default and click 'Finish'.
All the folder structure will be created automatically for you by system. Locate the folder
'war' and add a new folder called 'img'.
Add all your images that you want to host on Google App. Engine in 'img' folder.
-
Select the project from Eclipse and click Deploy web application.
You will be required to log in with Google app. Engine once and specify your application ID. Rest all
will be taken care by system automatically.
- If you have reached this step, then you have already created an application that would be LIVE on
YOUR_APP_NAME.appspot.com.
You can now see your images by directly going to this link:
YOUR_APP_ID.appspot.com
/img/IMAGE_NAME_WITH_EXTENSION
For e.g.
If you have an image with the name ABC.jpg, you should use the following URL:
YOUR_APP_ID.appspot.com
/img/ABC.jpg
This URL can be used in your own website and the image will be delivered/opened as part of your web
page. The only difference is that it will now be served on your web page by Google App. Engine instead
of your own web host.
That's it. You have set up Google App. Engine as your CDN for serving images. You can similary set up
folders for Javascript or CSS or any other type of file and use the URL in your own web site.
Setting up Google App. Engine to use custom Domain
-
Go to Google App Engine and click on 'Administration' -> 'Application Settings'. This menu would be
visible on left hand side pane.
-
Scroll down on 'Application settings' and find 'Domain SetUp' Option. click 'Add Domain' button.
NOTE: If you have not used
Google Applications earlier with your primary domain, you would need
to sign up with it first. Don't worry, you don't need to change anything in your original site.
Open
Google Applications and confirm domain ownership. Confirmation of your primary
domain is a one time activity. If you are have already done it, Google will only ask you to
create/change the mapping of your NEW sub-domain.
Else, you would be required to first confirm the ownership of primary domain and then come to mapping
step.
In our case, We use Google applications for managing our Blog's email and hence already with
it.
-
Add the primary domain in the add domain text box. E.g. We have specified am22tech.com. Click
'Add Domain'. Do NOT add the sub-domain that you want to map. Only primary domain is required.
You may be asked to log-in with Google Applications Admin user name and password. Log-in and you will
reach the following screen. Check the 'Accept' check box and click 'Activate this service' button.
-
Click 'Add new URL' link. Enter the word 'img' in the text box. Click 'Add' button.
You will now reach the instructions page for setting up sub-domain with your domain registrar
and point it to Google servers.
Here is what you should do now:
-
Create a sub-domain/custom domain with your domain host: Most domain registrar would allow you
to create sub-domain for your primary domain for free. We use Godaddy and they allow unlimited sub-
domains! We used img.am22tech.com for pointing to images stored on Google App. Engine.
Go to your DNS manager and create a new entry with the name as img pointing to Google server
ghs.google.com.
Save your changes. The example image here is shown from GoDaddy Domain manager control panel.
The mapping between custom domain and the Google App. Engine server is defined by the 'C
record' that you have just created.
-
Come back to Google page and click the 'I've completed these steps' button.
-
Once mapping has been saved and is activated on your web-host servers, you can immediately see it in
action by launching the sub-domain from your internet browser.
Thats it. You can now access the same image link by using your custom domain as follows:
img.YOUR_DOMAIN.com
/img/IMAGE_NAME_WITH_EXTENSION
For e.g.
If you have an image with the name ABC.jpg, you should use the following URL:
img.YOUR_DOMAIN.com/img/ABC.jpg
Bandwidth limitations and cost of using Google App. Engine?
Google App. Engine allows you to use certain amount of space and bandwidth to be used free of cost. If
your application uses more than thta, you need to buy that bandwidth and space. You can find out the
exact costs on this
link.
At the time of writing this article, the bandwidth is limited to 1GB per day with maximum free storage
available upto 5GB. Thereafter, Google charges $0.12 per GB.
I hope this helps. Let me know if you get stuck anywhere in the comments.
Related:
Set Up Custom Domain Email With Gmail And Google
Applications