How to Use GitHub for Hosting JavaScript and CSS files through Rawgit

Are you Facing problem in hosting JavaScript or CSS for your blogger website? Today in this article we are going to explain How to Host Free JavaScript and CSS For blogger on Github.

Use GitHub for Hosting JavaScript and CSS files through Rawgit

This is a great challenge to find a suitable free CDN (Content Delivery Network) with unlimited bandwidth. As a web developer and Blogger we often host JavaScript and CSS file on hosting service provider site. But you won’t do it freely with unlimited bandwidth. Formerly we has hosted our JavaScript files on Google Code but unfortunately Google stopped their service and they were open a new door for us that is called Google Drive.But similarly Goggle also discontinued serving content via Google Drive host.So we should find another way to host our JavaScript and CSS file in another server.

I have found a better alternative which is called Github. But you can host only JS and CSS file on Github but can’t load it on your Website. And for loading JS and CSS files you have to load through RawGit. RawGit serves raw files directly from GitHub with proper Content-Type headers.

However our main objective is to host JavaScript and CSS files on GitHub and load it on our Blog. But for this you can to go through 4 steps-

  1. Sign up With GitHub
  2. Creating a Repository on GitHub
  3. Creating a GitHub Project to host JS and CSS files
  4. Adding GitHub file or gist URL on RawGit for serving file on our Website.

So the total process looking little lengthy but don’t worry this is very easy. I will discuss it below step by step.

How to create an account on GitHub?


Step 1. First visit the Github
Step 2. Now Click On Sign Up Button.
Step 3. Now Create Your Username , Add email Address and password for creating account on Github.
Step 4. You will head to “Step 2” for choosing your Plan and from there select “Unlimited public repositories for free.” from the list. After that, click “Continue” button.
Step 5. Now Go to your email and activate the Github Account.

How to Creating a Repository on GitHub?


Step 1. Go to your “GitHub Dashboard” and click “Create new… “, “+” icon from top right corner to select “New repository”.
Step 2. You will head to “Create a new repository” page and write a name under “Repository name” field. Write your repository description under “Description” field but this is optional.
Step 3. Select radio button where written “Public”, thus anyone can see your repository.
Step 4. Put tick on “Initialize this repository with a README” option. As well as add Git ignore and License on your repository by using “Add .gitignore” & “Add a license” dropdown option.
Step 5. Finally click “Create repository” to go next level.

How to create a GitHub Project to host JavaScript or CSS files?


Step 1. Click “Create new file” from the top.
Step 2. Now you will see the Code Editor under “Code” tab.  First write your file name with appropriate extension like myfile.js or myfile.css and below “<>Edit new file” add your JavaScript or CSS code.
Step 3. After that scroll down and locate “Commit new file”, simply click on it.
Step 4. You see in example that myfile.js file has created click on the myfile.js file and copy the URL address from your browser address bar.  It will look like below.
https://github.com/USERNAME/RepositoryName/blob/master/myfile.js
So we have successfully host and published our JavaScript or CSS file in GitHub.

How to link the GitHub default URL with RawGit CDN for serving file on our Website


Step 1. First of all, navigate to Rawgit official website.
Step 2. Then, paste the default GitHub Link (which you copied on browser address bar [Part 3 & Step 4]) on the first input field.
Step 3. RawGit will provide you two different links first one for limited traffic and the second one for unlimited traffic or Production. Then just copy or use the 2nd link which is for Production.
Now your JavaScript file is ready to use on your blogger blog or website.

How to use hosted file from RawGit to blog or website?


After hosting file on GitHub and getting RawGit URL from your JavaScript or CSS file the URL would be like below-
https://cdn.rawgit.com/USERNAME/RepositoryName/master/myfile.js
Now you would like to use this JavaScript file on your blog or website. This is really easy to add GitHub hosted file on blog or website to make it work. But for hosting JavaScript file on blog or website the above JS file URL should write like below.
<script src="https://cdn.rawgit.com/USERNAME/RepositoryName/master/myfile.js" type="text/javascript"></script>

I hope now it is clear to you that how we can host any file on GutHub and make it work on our blog or website.

Berkenalan Dengan CSS

Mungkin sobat sudah sering mendengar tentang css, dan bagi beberapa sobat mungkin juga masih bingung tentang apa itu css, sama seperti saya hehehe....



Sebagi seorang blogger, apalagi webmaster or designer or whatever lah :D memahami css sangatlah penting, ya walaupun tidak secara keseluruhan, at least kita tahu lah apa itu css :)



Apa Itu CSS?



CSS adalah singkatan dari Cascading Style Sheets, yaitu suatu bahasa stylesheet yang digunakan untuk mengatur tampilan dokumen HTML.



CSS telah distandarisasi oleh W3C (World Wide Web Consortium) dan merupakan kumpulan dari tag html yang kita buat kedalam satu file dan dengan metode penulisan tertentu



Mengapa Harus Menggunakan CSS?



Sebenranya sih tanpa menggunakan css juga tidak apa-apa, toh HTML sendiri bisa kok mengatur tampilannya sendiri, tapi coba sobat bayangkan, jika mengelola suatu blog kemudian ingin merubah warna atau jenis text atau object tertentu, pasti akan ribet karena kita harus merubah satu per satu halaman html tersebut.



Dengan adanya css bisa membantu kita untuk mengatur tampilan si html, sehingga jika misalnya sobat memilik seratus halaman html maka kita tidak perlu merubahnya satu per satu, cukup dengan merubah css nya maka beres deh.





CSS



Cara Menggunakan CSS Di Dalam File HTML



Kita bisa menggunakan 3 cara untuk mengaplikasikan css di dalam html, yaitu Internal CSS, External CSS, dan Inline CSS



1. Internal CSS



Disebut internal karena kita menuliskan file css ini di dalam file html secara langsung (jadi satu dengan kode html-nya), contohnya sebagai berikut :


<html>
<head>
<title>CSS Pertamaku</title>
<style type="text/css">
p {color: white;}
body {background-color: black;}
</style>

</head>
<body>
<p>Ayo belajar CSS</p>
</body>
</html>

Yang berwarna biru itu adalah kode css yang mengatur tag p (paragraph)



2. External CSS



Berbeda dari Internal CSS, External CSS adalah file css yang tidak ditulis dalam file html secara langsung, file css ini berada terpisah dengan ekstensi .css dan dipanggil untuk mengatur html dibawahnya, contohnya sebagai berikut :


<html>
<head>
<title>CSS Pertamaku</title>
<link rel="stylesheet" type="text/css" href="file.css"/>
</head>
<body>
<p>Ayo belajar CSS</p>
</body>
</html>



Yang berwarna biru adalah lokasi file css dimana file tersebut berada pada folder yang sama dengan file html-nya.



3. Inline CSS



Jika Internal dan External CSS ditulis diantara tag <head> dan </head>, maka Inline CSS adalah penulisan secara langsung atau "gandeng" dengan kode html yang akan di atur oleh css tersebut, contohnya sebagai berikut :


<html>
<head>
<title>CSS Pertamaku</title>
</head>
<p style=”background: blue; color: white;”>Ayo belajar CSS</p>
</body>
</html>



Yang berwarna biru adalah script css.



Sintaks (Cara Penulisan) CSS



Secara garis besar, penulisan css menggunakan 3 komponen, yaitu : Selector, Property, dan Value. lebih tepatnya seperti ini selector {property1: value; property2:value; dst}.



Misalnya jika dalam file html menggunakan paragraf rata tengah penulisannya adalah <p align="center">, dimana p adalah tag dan align="center" adalah atributnya, maka untuk sintaks css nya adalah p {text-align: right;}.


  • Selector
    Selector pada CSS sama dengan tag atau komponen pada HTML yaitu yang terdapat antara tanda < dan tanda > misalnya <h1>, <p>, <b>, dll.

  • Property
    Property pada CSS sama dengan atribut pada HTML yaitu. berfungsi untuk memberi nilai dari selector.

  • Value
    Value adalah nilai yang kita berikan kepada property


Penulisan Comment Pada CSS



Seperti bahasa-bahasa lainnya, css juga mengenal adanya comment yang bertujuan untuk mempermudah kita ketika melakukan penulisan. Penulisan comment pada css adalah dengan kode pembuka /* dan ditutup dengan kode */ contoh


/* ini comment, ga bakal dieksekusi */



Penggunaan Class dan Id Selector Pada CSS



Class Selector

Class Selector adalah penggunaan beberapa selector yang digunakan lebih dari satu kali. Untuk menuliskan class pada css dimulai dengan dot atau titik.


/* diawali dengan titik (dot) */
.nama-class {property:value;}
.testing {font-size: 12px;}



Jika ingin menempelkan class pada tag html maka penulisannya adalah


/* diawali dengan tag html dan titik */
taghtml.nama-class {property:value;}

h2.testing {font-size: 18px;}



Jika menggunakan class selector diluar tag html maka harus ditulis diantara <div class="nama-class"> dan </div>, contoh :


<div class="testing">

<h1>belajar css</h1>

</div>



Untuk class yang menempel pada tag html maka penulisaanya adalah <tag html class="class-name"></tag html>, contoh :


<h1 class="testing">belajar css</h1>

Id Selector

Id Selector sebenarnya sama dengan class selector, perbedaanya hanyalah pada penggunaan dan penulisan sintaksnya. Id selector adalah selector yang hany boleh dipakai sekali dalam keselurah file html. Untuk penulisan id selector adalah dengan menggunakan pagar.


/* diawali dengan tanda pagar */
#id-class {property:value;}

#bunting {font-size: 12px;}



Untuk selector yang menempel pada tag html maka penulisannya adalah


/* diawali dengan tag html dan pagar */
taghtml#id-class {property:value;}

h2#bunting {font-size: 18px;}



Untuk penggunaannya sama dengan class selector dimana jika digunakan diluar tagh html maka harus ditulis diantara <div id="id-class"> dan </div>, hanya beda di class dan id saja, contoh


<div id="bunting">

<h1>belajar css</h1>

</div>


<h1 id="bunting">belajar css</h1>

Ada banyak keuntungan jika kita bisa memahami css serta mengaplikasikan css, contohnya ketika melakukan optimasi seo on page dengan tag heading dinamis dimana css bisa digunakan untuk mengatur besar font ketika menjadi H1 dan H2 agar terlihat sama dan tidak amburadul.


Itulah sekelumit pengethuan saya tentang css hasil dari searching di mbah Google, semoga bermanfaat.