Originally Posted by
Design75
Yeah, the answer may have been a bit lame, people tend to forget there is a big world with information outside this community.
You can use async for javascripts and media="screen" for stylesheets
It doesn't work for all of them but works for some. Also compressing all stylesheets into one doesn't always work due to the Zen Cart architecture.
This is what I suggest:
In templates/YOUR_TEMPLATE/common/html_header.php
Look for where it links to your stylesheets
For example:
PHP Code:
while(list ($key, $value) = each($directory_array)) { echo '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . $value . '" />'."\n"; }
and change it to:
PHP Code:
while(list ($key, $value) = each($directory_array)) { echo '<link media="screen" rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . $value . '" />'."\n"; }
Note where it now says media="screen"
There is one entry for mobiles which I changed too where the styles aren't required for desktops or laptops:
PHP Code:
$responsive_mobile = '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'responsive_mobile.css' . '"
changed to
PHP Code:
$responsive_mobile = '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'responsive_mobile.css' . '" media="(min-width: 53.333em)"
HTML Code:
media="(min-width: 53.333em)"
only renders the mobile stylesheet once the screensize reduces to 640px
Javascript is slightly different.
Look for where it says:
HTML Code:
<script type="text/javascript"
and change it to:
HTML Code:
<script async type="text/javascript"
I suggest testing as well, don't do this on a live site. AND BACKUP before you do the work. The results can be a little sketchy but you increase your page speed.
I also added into htaccess:
HTML Code:
<IfModule mod_headers.c> <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|svg)$"> Header set Cache-Control "max-age=84600, public" </FilesMatch> <FilesMatch "analytics\.(js)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "stylesheet\.(css)$"> Header set Cache-Control "max-age=604800" </FilesMatch> <FilesMatch "jquery.mmenu.min.all\.(js)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "responsive_mobile\.(css)$"> Header set Cache-Control "max-age=604800" </FilesMatch> <FilesMatch "jquery.mmenu.all\.(css)$"> Header set Cache-Control "max-age=604800" </FilesMatch> <FilesMatch "jquery.nivo.slider.pack\.(js)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "stylesheet_colors\.(css)$"> Header set Cache-Control "max-age=604800" </FilesMatch> <FilesMatch "jscript_imagehover\.(js)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "index_home\.(css)$"> Header set Cache-Control "max-age=604800" </FilesMatch> <FilesMatch "responsive\.(css)$"> Header set Cache-Control "max-age=604800" </FilesMatch> <FilesMatch "stylesheet_zen_colorbox\.(css)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "jscript_matchHeight-min\.(js)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "stylesheet_css_buttons\.(css)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "stylesheet_flexible_footer_menu\.(css)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "print_stylesheet\.(css)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "jquery.mmenu.fixedelements.min\.(js)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "style_imagehover\.(css)$"> Header set Cache-Control "max-age=31536000" </FilesMatch> <FilesMatch "p\.(css)$"> Header set Cache-Control "max-age=31536000" </FilesMatch></IfModule>
And applied compression through CPANEL.
All of these combined, took my page speed up from around between 50% - 60% up to 85% - 98%
Bookmarks