Skip to content

Instantly share code, notes, and snippets.

View salscode's full-sized avatar

Sal Sodano salscode

View GitHub Profile
@salscode
salscode / gzip-font-writeup.md
Last active February 4, 2023 17:15
Enabling Gzip in .Htaccess

If you use @font-face (like I do) to enable cool custom fonts on your website, please read this article. I love @font-face to more effectively choose nice fonts for my website, but I never liked the 200-400 KB .ttf files that the user had to download in order to view the fonts. I did a little research and realized that I could simply add these heavy files to the Gzip process in my .Htaccess file (If you would like to read more about Gzip, click here). Turns out that it is very simple, just specify the type that you want to be added along with its corresponding file extension, then add that file type to your current list of file types to Gzip, below is the code needed to Gzip all files along with .ttf, .otf and .eot (three file types used in the @font-face process).

Code

Here is the code that enables Gzip for only .otf, .eot and .ttf files.

<ifmodule mod_deflate.c>
<ifmodule mod_mime.c>   #Checks if your server supports Addtype
Addtype font/opentype .otf
Addtype font/eot .eot
Addtype font/truetype 
<?php
require_once("rblcheck.php");
function cidrToRange($cidr) {
$cidr = explode('/', $cidr);
$firstIP = ip2long($cidr[0]) & (-1 << (32 - (int)$cidr[1]));
$lastIP = $firstIP + pow(2, (32 - (int)$cidr[1])) - 1;
$range = array();
for($firstIP; $firstIP <= $lastIP; $firstIP++)