Sharing Information
Sharing Information
Picture of the author
Pankaj PawarinPHP
17th Sept 24.07:00 Min.
https://sharinginfo.in/php/codeigniter-htaccess-index-php-mod-rewrite-rule-seo-url-rewrite-rule-32.html

CodeIgniter, htaccess, index.php, mod rewrite rule, SEO, url rewrite rule

CodeIgniter, htaccess, index.php, mod rewrite rule, SEO, url rewrite rule
Photo by Simon Abrams on Unsplash

How to improve page speed or page loading time? This question lots of time ask and search online. Reason behind this question is, today we have used lot’s type of web font, different type CSS to look and feel and in now days CSS Transitions on your website and the vast area cover by java script for animation and other use.

In this situation we can not remove Java Script, CSS or Image from our website. We need to find some solution on this problem. We will solve this problem by caching your CSS, Java Script or images which is not change regularly.

We need to remember When you are writing content or adding images in content, images must be minifyed and content is not more than 250KB as per SEO rules.

Now i will have some code to leverage cache and minify your HTML on the fly.

Keep maximum your Java Script, CSS, Images expiry time this will effect on you Page Load Speed (PageSpeed) and increase by 20%, But keep in mind your uploaded images is always compressed and its not more than 120 kb or 180 kb.

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

Above code will affect on your Java Script, CSS, Image, PHP and on HTML and increase you page speed.

Now Below code is my favorite it will compress your HTML and decrease HTML page loading time.

function sanitize_output($buffer) {
$search = array(
'/\&gt;[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\&lt;/s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'&gt;',
'&lt;',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");

Place above code in your index.php or the root PHP file which run first when your template or page will be load.

Sharing Info Cookie Consent

Our website uses cookies to improve your browsing experience and relevant content delivery. Before continuing to use our website, you agree & accept of our Cookie Policy & Privacy.