Post by iDragonFly^ » Sun Jan 03, 2021 11:44 pm

My website has Home page speed problem, (The home page is loading so many CSS and JS files by the theme and attached plugins) , I'm trying to fix it and also I came up with the following htaccess caching codes which solved some of the problem, after using this code, I had a problem with the admin backend caching system, the modification refresh function is not working, but when I delete the codes in htaccess file things back to normal... My question is

1- How to exclude the admin backend from this code and is this completely correct code for my website to use?

2- My website is https and has two themes (desktop and mobile theme), https:www.website.com/index.php?route=common/home was redirected to https:www.website.com with an extension which did the job. Mobile theme's original url is: "/index.php?route=extension/mobile/home" I want to make it into "https://www.website.com/mobile"

P.S:Using Opencart Version 3.0.3.2

Any help & correction is appreciated
By the way the advices were given by IP_CAM on this artical viewtopic.php?t=207490 are very helpful..thanks for him! :)

the htaccess code that i have:

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks


# Rabbit Rabbit Security Upgrade 02/03/2016
Options +SymLinksIfOwnerMatch

# Prevent Directory listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|.twig|\.ini|\.log|(?<!robots)\.txt))">
## For apache 2.2 and older, replace "Require all denied" with these two lines :
# Order deny,allow
 Order deny,allow
 Deny from all
</FilesMatch>

# disable etags
FileETag none

# SEO URL Settings
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^system/storage/(.*) 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>

### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

Newbie

Posts

Joined
Sat Mar 10, 2018 7:56 pm

Post by IP_CAM » Mon Jan 04, 2021 12:28 am

One simple way would be, to implement all CSS File Content
into the default stylesheet.css, and then compress that file.
Then, you just have to remove all the links, directing to the formerly
individual CSS Files, whereever they exist.
As well as compressing all the existing JS Files individually as well:
https://www.giftofspeed.com/tools/
You then get a one-liner stylesheet.css file as result of this, and most JS
Scriptings can be compressed the same way. Some can even be 'combined' into
one file too, but that's a little more complicated, just to have it mentioned too ... :D
And if you do it right, it will end up in a speedy one-liner Source, as it can be seen here:
http://www.opencart.li/shop/
---
Image

My Github OC Site: https://github.com/IP-CAM
5'200 + 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 victorj » Mon Jan 04, 2021 12:34 am

Make sure there is a .htaccess file in your admin folder.
it can be empty.

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Alle niet stekplichtige onderdelen zoals scharnieren, sloten, randverwarming en verlichting voor alle typen koelingen en vriezers.
https://koelcel-onderdelen.com


User avatar
Expert Member

Posts

Joined
Sat Jun 25, 2011 4:09 am
Location - Alkmaar Holland

Post by ADD Creative » Mon Jan 04, 2021 6:02 am

iDragonFly^ wrote:
Sun Jan 03, 2021 11:44 pm

Code: Select all

 ExpiresDefault "access plus 1 week"
Setting the expires header for responses from PHP can cause problems at checkout, especially in some browsers.

viewtopic.php?f=202&t=206449#p786660

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by paulfeakins » Mon Jan 04, 2021 7:46 pm

iDragonFly^ wrote:
Sun Jan 03, 2021 11:44 pm
Any help & correction is appreciated
You might as well just start again with a decent theme like:
https://www.opencart.com/index.php?rout ... n_id=36706

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by iDragonFly^ » Tue Jan 05, 2021 2:17 am

Thanks guys for replies and suggestions!
IP_CAM wrote:
Mon Jan 04, 2021 12:28 am
One simple way would be, to implement all CSS File Content
into the default stylesheet.css, and then compress that file.
Then, you just have to remove all the links, directing to the formerly
individual CSS Files, whereever they exist.
As well as compressing all the existing JS Files individually as well:
https://www.giftofspeed.com/tools/
You then get a one-liner stylesheet.css file as result of this, and most JS
Scriptings can be compressed the same way. Some can even be 'combined' into
one file too, but that's a little more complicated, just to have it mentioned too ... :D
And if you do it right, it will end up in a speedy one-liner Source, as it can be seen here:
http://www.opencart.li/shop/
---
i already did compressed most of the CSS and JS files, but i'll try to combine files, it may help..
I have seen your reply in this post for an older version of opencart, but # Leverage Browser Caching is causing the problem in checkout page. :(
viewtopic.php?t=161164
victorj wrote:
Mon Jan 04, 2021 12:34 am
Make sure there is a .htaccess file in your admin folder.
it can be empty.
The admin directory is without htaccess file by default, as you mentioned that i have to add htaccess file in admin dir, what codes should i put in? i may give it a try, but the problem i think can still be existed for the checkout page. :(
ADD Creative wrote:
Mon Jan 04, 2021 6:02 am
iDragonFly^ wrote:
Sun Jan 03, 2021 11:44 pm

Code: Select all

 ExpiresDefault "access plus 1 week"
Setting the expires header for responses from PHP can cause problems at checkout, especially in some browsers.

viewtopic.php?f=202&t=206449#p786660
Yes, correct, it causes problems in checkout and switching between payment and shipping methods, i tried the way was mentioned in the post you suggested, it worked the same as before, as there is not caching codes in htaccess. :-\
paulfeakins wrote:
Mon Jan 04, 2021 7:46 pm
iDragonFly^ wrote:
Sun Jan 03, 2021 11:44 pm
Any help & correction is appreciated
You might as well just start again with a decent theme like:
https://www.opencart.com/index.php?rout ... n_id=36706
I may try it in future because the theme that i'm using now already got custom modifications and it's hard to transfer them to a new theme. :)

Newbie

Posts

Joined
Sat Mar 10, 2018 7:56 pm

Post by iDragonFly^ » Tue Jan 05, 2021 2:19 am

The problem that I found was in this piece of code only:

Code: Select all

# 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>
The good thing of this code is that it loads pages so fast for the second time browsing, which I need it especially in my mobile theme, when users browsing on mobiles.
I tried this cache-control code instead and it worked fine, also the Checkout process was working without issues, BUT pages weren't loading as fast as Leverage caching code.

Code: Select all

# 1 Month for most static assets
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>

Newbie

Posts

Joined
Sat Mar 10, 2018 7:56 pm

Post by iDragonFly^ » Tue Jan 05, 2021 2:27 am

One more thing plz, what causing the following error? Is it related to the haccess file that i use?

I see it when on Chrome>Inspect> Console

Code: Select all

Failed to load resource: the server responded with a status of 404 ()     /image/loading.svg:1
Should I use resources provided in this post to fix it?
viewtopic.php?t=186311

Newbie

Posts

Joined
Sat Mar 10, 2018 7:56 pm

Post by ADD Creative » Tue Jan 05, 2021 3:17 am

iDragonFly^ wrote:
Tue Jan 05, 2021 2:17 am
Thanks guys for replies and suggestions!
ADD Creative wrote:
Mon Jan 04, 2021 6:02 am
iDragonFly^ wrote:
Sun Jan 03, 2021 11:44 pm

Code: Select all

 ExpiresDefault "access plus 1 week"
Setting the expires header for responses from PHP can cause problems at checkout, especially in some browsers.

viewtopic.php?f=202&t=206449#p786660
Yes, correct, it causes problems in checkout and switching between payment and shipping methods, i tried the way was mentioned in the post you suggested, it worked the same as before, as there is not caching codes in htaccess. :-\
You need both the bug fix to system/framework.php and your ExpiresByType/ExpiresDefault in htaccess. That way all static files will be cached, but dynamic PHP responses won't.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by victorj » Tue Jan 05, 2021 6:29 am

if you have a .htaccess in your root folder, it will pass everything in that file to any folder.
in your case your caching a lot og things and that also applys to your admin folder.
if you plave a .htaccess file in your admin folder it wont follow rules from your root.
.htaccess file does nit have to contain any lines, just leave it emty.

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Alle niet stekplichtige onderdelen zoals scharnieren, sloten, randverwarming en verlichting voor alle typen koelingen en vriezers.
https://koelcel-onderdelen.com


User avatar
Expert Member

Posts

Joined
Sat Jun 25, 2011 4:09 am
Location - Alkmaar Holland

Post by iDragonFly^ » Mon Jan 11, 2021 9:18 am

I added this code and it seems working fine..

Code: Select all

<FilesMatch "\.(php)$">
    <IfModule mod_expires.c>
        ExpiresActive Off
    </IfModule>
    <IfModule mod_headers.c>
        Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
    </IfModule>
</FilesMatch>

Newbie

Posts

Joined
Sat Mar 10, 2018 7:56 pm
Who is online

Users browsing this forum: Google [Bot], SohBH and 276 guests