Post by pinklotus » Sun Apr 17, 2016 3:55 am

Hi,

I have OC version 1.5.6.4

What code do I need to add to my .htaccess file for leverage browser caching (1 week)?

Site: http://www.4rissa.com

I am still a beginner at this and help is greatly appreciated :)

Thanks in advance
Rissa

cialispascherfr24 pharmacy


New member

Posts

Joined
Sat May 30, 2015 6:35 am

Post by oc-extensions » Sun Apr 17, 2016 7:33 am

Hi,

Read this article and will find exactly what you need;

https://varvy.com/pagespeed/leverage-br ... ching.html

Image | Extensions and Custom Development


User avatar
Active Member

Posts

Joined
Fri Jan 06, 2012 11:31 pm

Post by IP_CAM » Sun Apr 17, 2016 9:43 am

or easier, just download and use the most powerful and speedy .htaccess in the North, South, East and West!
Just make sure, to re-declare this, to make it work, depending on the /Shop/ Subdirectory-Name:
RewriteBase /shop/
I use it in my latest TestShop ipc.li, among a few other Gizmo's, to finally get a 98/92 at GTMetrix.
---

Code: Select all

# Rabbit Rabbit Security Upgrade, enhanced by Ernie 04/10/2016
Options +SymLinksIfOwnerMatch

# Prevent Directory listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
 Order deny,allow
 Deny from all
</FilesMatch>

# disable etags
FileETag none

# SEO URL Settings
RewriteEngine On
RewriteBase /shop/
 
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

# Enable Gzip Compression
AddOutputFilterByType DEFLATE text/text
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
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon

# Remove Browser Bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

<IfModule mod_deflate.c>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

# cache gif, jpg, and png files for one week
<FilesMatch ".(gif|jpg|png)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>

# Leverage Browser Caching
<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresByType image/jpg "access plus 1 week"
 ExpiresByType image/jpeg "access plus 1 week"
 ExpiresByType image/gif "access plus 1 week"
 ExpiresByType image/png "access plus 1 week"
 ExpiresByType text/css "access plus 1 week"
 ExpiresByType application/pdf "access plus 1 week"
 ExpiresByType text/x-javascript "access plus 1 week"
 ExpiresByType application/x-shockwave-flash "access plus 1 week"
 ExpiresByType image/x-icon "access plus 1 week"
 ExpiresDefault "access plus 1 week"
</IfModule>
Good Luck ;)
Ernie

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by pinklotus » Sun Apr 17, 2016 11:15 am

Thanks Ernie! Worked like a charm :)

Now, I would like to compress the total page size (3.07MB). How can I do this?

Latest performance report by gtmetrix: https://gtmetrix.com/reports/www.4rissa.com/B8IATiP6

cialispascherfr24 pharmacy


New member

Posts

Joined
Sat May 30, 2015 6:35 am

Post by IP_CAM » Mon Apr 18, 2016 5:34 am

Set your compression level in your Admin/System/Server environment to minimal 5. And if you get an error Page afterwards, set it back to 0, for the time beeing...
But you use very large images, seemengly, so, you would have to shrink/compress them, in DATA-Size first. Also, you have to add WIDTH+ HEIGHT tags to your images, you'll find such Mod's in the Extension Section.
http://www.opencart.com/index.php?route ... ght%20tags

And to go one more step, by example, by renaming the DEFAULT system/library/responsive.php to responsive2.php, to keep it, in any case, and creating a file out of this responsive.php content, and upload it to the system/library/... Subdirectory instead.

BUT, since it will totally 'visually deform' your html output, you will not longer be able to 'see' much usable Page Source, if you look at a Page, from the Source View, at least, used usually, to see, if a page has been build correctly. Therefore, if you ever use that way of looking, you first need to reswitch back to the DEFAULT responsive.php, to have a full page clear View on it. The modified Source will then look like on this Page, when looking at from the SOURCE VIEW. But it add's another percentage point or two, to performance test results.
http://www.ipc.li/shop/index.php?route= ... ry&path=18

Good Luck ;)
Ernie
---

Code: Select all

<?php
class Response {
	private $headers = array();
	private $level = 0;
	private $output;

	public function addHeader($header) {
		$this->headers[] = $header;
	}

	public function redirect($url, $status = 302) {
		header('Location: ' . str_replace(array('&', "\n", "\r"), array('&', '', ''), $url), true, $status);
		exit();
	}

	public function setCompression($level) {
		$this->level = $level;
	}

	public function setOutput($output) {
		$this->output = $output;
	}

	public function getOutput() {
		return $this->output;
	}

	private function compress($data, $level = 0) {
		if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false)) {
			$encoding = 'gzip';
		}

		if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false)) {
			$encoding = 'x-gzip';
		}

		if (!isset($encoding) || ($level < -1 || $level > 9)) {
			return $data;
		}

		if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) {
			return $data;
		}

		if (headers_sent()) {
			return $data;
		}

		if (connection_status()) {
			return $data;
		}

		$this->addHeader('Content-Encoding: ' . $encoding);

		return gzencode($data, (int)$level);
	}

	public function output() {
		
		if ($this->output) {
			
			if ($this->level) {
				$output = $this->compress(minify($this->output), $this->level);
			} else {
				$output = minify($this->output);
			}

			if (!headers_sent()) {
				foreach ($this->headers as $header) {
					header($header, true);
				}
			}

			echo $output;
		}
	}
}


function minify($html)
{
	$html = preg_replace("`>\s+<`", "> <", $html);
	$replace = array(
		'&nbsp;' => '&#160;',
		'&copy;' => '&#169;',
		'&acirc;' => '&#226;',
		'&cent;' => '&#162;',
		'&raquo;' => '&#187;',
		'&laquo;' => '&#171;'
	);
	return $html;
}		
?>

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: No registered users and 14 guests