•
Very often we need to take a backup of a website, i.e. download the website for offline use. There could be several reasons for this, one of-course is simply for backup purposes. Other reasons could be to view or modify the source code of a 3rd party website. It can also be used to take a "snapshot" of a dynamic website. Note any HTML content rendered using ajax may not get backed up.
Using wget to clone the website
wget -mkEpnp <URL of website to clone>
Yep, Thats it! This command will clone all HTML, CSS, JS, Images and other content accessible from this page. Its recursive in nature so it will also clone content from all pages linked from this page. Wget is a free software package for retrieving files using HTTP, HTTPS, FTP and FTPS the most widely-used Internet protocols. There are several options possible, check them out using wget -help
.
Host it locally, easily
If efficiency is required, you can install Nginx or Apache and use it to host the static content. However for most cases that is overkill and defeats the purpose.
Using Python SimpleHTTPServer to serve static content
Simply navigate to the directory
python -m SimpleHTTPServer < port number >
Now simply share your local IP address, for the clients to view the static content.
Hosting it globally for free, using github pages
To serve static content you can use Amazon AWS S3 Storage or setup a VM on DigitalOcean which will require configuring of nginx or apache. However this may take time and cost money and is therefore not desirable.
Push static website to github
- Sign up on Github
- Install git on your machine's command line
- Navigate to your cloned website's root folder (index.html should be there)
- Execute
git init
, to create your repository - Execute
git add .
, to add all static content to staging area - Execute
git commit -m "my static website"
to create a commit - Create a new repo on github, make sure to uncheck "Initialize this repository with a README"
- Execute the instruction under "push an existing repository from the command line" in your github repo
We are nearly done!
Publish static website as github pages
- Navigate to settings page on github
- Scroll down to Github Pages
- Chose master branch and click save
You should be able to see a URL now, congrats your website is live and global!
If you have a custom domain, you can link it to github pages