Speed up your website with gzip compression

What is GZIP Compression

You need to enable GZIP compression on your website to reduce load time of your website. Sharp website development and aggressive search engine optimization (SEO) is vital for every website but adding heap of content takes it tool on your website’s viewership. Research shows that your website will leave your website if it made them more than 20 seconds. Modern website designs are incomplete without CSS, Java scripts, PHP and images but sometimes these things piles so much that they choke the bandwidth of the consumer and consumers leave your website disgruntled after your website loading lower than the speed of a snail.

Benefit of Enabling GZIP Compression

By enabling compression for your website, it’ll simply compress the items browser needs to download to load your website. It will reduce the webpage load by 50 to 70% and it will keep your customer or viewer keep stuck to your website.

How enable GZIP Compression?

If your website is running on apache webserver, you can enable compression for your website by just copying the following code and paste it in your .htaccess file (can be found in the www or public html directory of your website.

 

[php] #Enable Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can’t Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
[/php]

Give the code time of 2-3 hours to propagate itself and then check upon your website if it has enabled or not.If code given above doesn’t work out, remove the above code and add the code given below instead.

 

[php] AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE text/xml

AddOutputFilterByType DEFLATE text/css

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE application/rss+xml

AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE application/x-javascript
[/php]

 

You can reach Waqas Yousaf through twitter @wiqi.

Read More
Waqas Yousaf October 12, 2016 22 Comments

PHP Date and Time Reference | Cheatsheet

Why Do I Need PHP Date And Time Refernce?

Need for a PHP date and time reference arose when I was working on a blog and I had to check for the date and time functions every now and then. Let me admit something here. Nobody is a perfect programmer. We usually need references and cheatsheets to get out word done quickly. PHP like every other maintained programming language has like thousands if not millions of function names and parameters.
I cannot remember all the functions and classes for a specific task. I simply needed an online reference for PHP date time functions so that I dont have to go snoop around like 30 pages to find one itsy bitsy function.

date() Function

date() month pretty much handy while you are dealing with date/time functionality in PHP. for example

[php]print date("d-m-Y");[/php]
Output:  05-07-2016

this function would print current date in simple day-month-year format as shown above.

[php]date("h:i:s")[/php]
Output:  10:37:58

and this function would print time in mundane hour:minutes:seconds format as given below

You can also add other details like day and am/pm as well.

[php]print date("l d-m-Y h:i A");[/php]
Output:  Tuesday 05-07-2016 10:44 AM

If you wanted to check if a date exists or not, you can use checkdate(‘m’,’d’,’Y’) function
It works something like this

[php]$check = (checkdate(20, 10, 1985)) ? "TRUE" : "FALSE";
print $check; [/php]
Output:  FALSE

It would print false as output because 20th doesnt exist. or does it?

date_create() Function

There’s a date_create() function to create an date object so date/time funcsionality.

[php]$date = date_create();
var_dump($date);
[/php]
Output:  object(DateTime)[1]
public 'date' => string '2016-07-02 09:06:20' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)

 

date_diff() Function

date_diff() is a function that gives out the interval between two given dates.

[php]

$date1 = date_create("2013-03-15");
$date2 = date_create("2013-12-12");
$diff = date_diff($date1,$date2);
var_dump($diff) ;
[/php]

Output:  object(DateInterval)[3]
public 'y' => int 0
public 'm' => int 8
public 'd' => int 27
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 0
public 'days' => int 272
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0

 

date_format() Function

date_format() is a function to format date as provided.

[php]$date=date_create("1999-07-30");
print date_format($date,"d-m-Y");[/php]
Output:  30-07-1999

 

time() Function

time() function gives you current epoch or unix time.

[php]print time();[/php]
Output:  1467707548

 

gmdate() Function

You can format the output in human reabible using gmdate() function

[php] $unixTime = time();
print gmdate(‘l h:i:s d-m-Y’, $unixTime);
[/php]
Output:  Tuesday 10:09:13 05-07-2016

 

strtotime Function

function returns relative time,string unix timestamp format.

[php]print strtotime("now");
print strtotime("12 December 2009");
print strtotime("+8 hours");
print strtotime("+1 week");
print strtotime("+1 week 3 days 7 hours 5 seconds");
print strtotime("next Friday");[/php]

 

Output:  1260572400
1467738028
1468314028
1468598433
1467928800

 

Relative Time Function

Here’s one script I have found on github to find relative time.

Just copy above above function and then you can use it in your program like

[php]print time2str(strtotime("10-june-2016"));[/php]

And the output would be something like this

Output:  4 weeks ago

 

You can reach Waqas Yousaf through twitter @wiqi.

Read More
Waqas Yousaf August 12, 2016 1 Comment

5 Handy Tools For Website Developers

In the business of web development and designing, unlike other designing fields, a website creator gets to use many tools in the process. These tools ranging from itsy bitsy notepad to humongous corporate solutions are the part of everyday work of a website developer. We have decided to link 5 wee tools that will make a web designer’s job easier and they are also absolutely free.

ConvertIcon

www.converticon.com

These days you don’t have to be a Photoshop expert to create the icons for your website. Just crop the logo and upload it on this website and it will create a downloadable icon file for your website.

Brackets by Adobe

www.brackets.io

Brackets is open source code editing tool developed by adobe and it’s absolutely free. It’s not only light weight and easy on computer resources but it has many features that other markup language editors just don’t have.

Opera Mobile Emulator

www.opera.com/developer/mobile-emulator

We are living in mobile age and every website is now coming with responsive website. So, if you are developing a mobile friendly responsive website, then you should have this utility on your system for a quick preview of your work

font dragr

www.fontdragr.com

Choosing the right font for the website is quite hard and tedious task. Font dragr is an online tool to test the font design without having them imported by just simply dragging the font file to the webpage.

Nibbler

www.nibbler.silktide.com

Want to test your website performance? This website would review your website and give you overall report for your website ranging from website design to the social media link and website code validation

Read More
Waqas Yousaf September 13, 2015 0 Comments