Jump to content

Darmowy moduł przyspieszający działąnie prestashop 1.6.x.x


grennet

Recommended Posts

Przetestujcie czy u was także na wersji 1.6.x.x jest znaczna poprawa otwierania zakładek, zdjęć itp.

Moduł sam dostosowuje dla danego sklepu alternatywną wydajność.

A mianowicie: 

Moduł optymalizacyjny dla PrestaShop 1.6.x, który włącza kilka podstawowych mechanizmów przyspieszających sklep.
Nie będzie to pełny „PageSpeed Booster”, ale baza, którą możesz rozbudować.

👉 Co może zrobić taki moduł:

włączyć cache Smarty i ustawić tryb kompilacji na optymalny,

włączyć CCC (Combine, Compress, Cache) dla CSS, JS i HTML,

włączyć cache w PrestaShop,

wymusić gzip/deflate w nagłówkach (jeśli serwer pozwala),

opcjonalnie wstrzyknąć nagłówki do .htaccess (expires headers, cache control).

W załączniku moduł :

Poniżej kod  convert-to-webp.php  który musisz wgrać w utworzony plik php o nazwie convert-to-webp.php 

<?php
if (!defined('_PS_VERSION_'))
    exit;

class SpeedBooster extends Module
{
    public function __construct()
    {
        $this->name = 'speedbooster';
        $this->tab = 'administration';
        $this->version = '1.0.0';
        $this->author = 'Custom';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->l('Speed Booster');
        $this->description = $this->l('Prosty moduł przyspieszający sklep PrestaShop 1.6.x.');
    }

    public function install()
    {
        if (!parent::install()) {
            return false;
        }

        // Włączenie cache Smarty
        Configuration::updateValue('PS_SMARTY_CACHE', 1);
        Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', 0);

        // CCC - Combine, Compress, Cache
        Configuration::updateValue('PS_CSS_THEME_CACHE', 1);
        Configuration::updateValue('PS_JS_THEME_CACHE', 1);
        Configuration::updateValue('PS_JS_DEFER', 1);
        Configuration::updateValue('PS_HTML_THEME_COMPRESSION', 1);
        Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', 1);
        Configuration::updateValue('PS_CSS_HTML_THEME_COMPRESSION', 1);

        // Cache PrestaShop
        Configuration::updateValue('PS_CACHE_ENABLED', 1);

        return true;
    }

    public function uninstall()
    {
        if (!parent::uninstall()) {
            return false;
        }

        // Przywrócenie domyślnych ustawień (opcjonalnie)
        Configuration::updateValue('PS_SMARTY_CACHE', 0);
        Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', 1);
        Configuration::updateValue('PS_CSS_THEME_CACHE', 0);
        Configuration::updateValue('PS_JS_THEME_CACHE', 0);
        Configuration::updateValue('PS_JS_DEFER', 0);
        Configuration::updateValue('PS_HTML_THEME_COMPRESSION', 0);
        Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', 0);
        Configuration::updateValue('PS_CSS_HTML_THEME_COMPRESSION', 0);
        Configuration::updateValue('PS_CACHE_ENABLED', 0);

        return true;
    }
}

 

Testujcie, u mnie teraz wszystko działa dosłownie na klik.

 

 

speedbooster.zip

Link to comment
Share on other sites

1 minute ago, grennet said:

A teraz dodaję do testów Zaktualizowany moduł speedbooster.php

 Fragment, który po instalacji sprawdzi plik .htaccess i dorzuci do niego reguły nagłówków cache (expires + cache-control). Dzięki temu przeglądarka szybciej będzie serwować statyczne pliki (CSS, JS, obrazy, fonty).

 

Możesz sobie podmienić zawartość speedbooster.php w module

<?php
if (!defined('_PS_VERSION_'))
    exit;

class SpeedBooster extends Module
{
    public function __construct()
    {
        $this->name = 'speedbooster';
        $this->tab = 'administration';
        $this->version = '1.1.0';
        $this->author = 'Ja';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->l('Speed Booster');
        $this->description = $this->l('Prosty moduł przyspieszający sklep PrestaShop 1.6.x z ustawieniami cache i nagłówkami .htaccess.');
    }

    public function install()
    {
        if (!parent::install()) {
            return false;
        }

        // Włączenie cache Smarty
        Configuration::updateValue('PS_SMARTY_CACHE', 1);
        Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', 0);

        // CCC - Combine, Compress, Cache
        Configuration::updateValue('PS_CSS_THEME_CACHE', 1);
        Configuration::updateValue('PS_JS_THEME_CACHE', 1);
        Configuration::updateValue('PS_JS_DEFER', 1);
        Configuration::updateValue('PS_HTML_THEME_COMPRESSION', 1);
        Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', 1);
        Configuration::updateValue('PS_CSS_HTML_THEME_COMPRESSION', 1);

        // Cache PrestaShop
        Configuration::updateValue('PS_CACHE_ENABLED', 1);

        // Dodaj nagłówki cache do .htaccess
        $this->updateHtaccess();

        return true;
    }

    public function uninstall()
    {
        if (!parent::uninstall()) {
            return false;
        }

        // Przywrócenie domyślnych ustawień
        Configuration::updateValue('PS_SMARTY_CACHE', 0);
        Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', 1);
        Configuration::updateValue('PS_CSS_THEME_CACHE', 0);
        Configuration::updateValue('PS_JS_THEME_CACHE', 0);
        Configuration::updateValue('PS_JS_DEFER', 0);
        Configuration::updateValue('PS_HTML_THEME_COMPRESSION', 0);
        Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', 0);
        Configuration::updateValue('PS_CSS_HTML_THEME_COMPRESSION', 0);
        Configuration::updateValue('PS_CACHE_ENABLED', 0);

        return true;
    }

    private function updateHtaccess()
    {
        $htaccess = _PS_ROOT_DIR_.'/.htaccess';

        if (!is_writable($htaccess)) {
            return false;
        }

        $rules = "
# SPEEDBOOSTER CACHE HEADERS
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg \"access plus 1 year\"
    ExpiresByType image/jpeg \"access plus 1 year\"
    ExpiresByType image/gif \"access plus 1 year\"
    ExpiresByType image/png \"access plus 1 year\"
    ExpiresByType text/css \"access plus 1 month\"
    ExpiresByType application/pdf \"access plus 1 month\"
    ExpiresByType text/javascript \"access plus 1 month\"
    ExpiresByType application/javascript \"access plus 1 month\"
    ExpiresByType application/x-javascript \"access plus 1 month\"
    ExpiresByType application/x-shockwave-flash \"access plus 1 month\"
    ExpiresByType image/x-icon \"access plus 1 year\"
    ExpiresDefault \"access plus 7 days\"
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch \"\\.(ico|jpe?g|png|gif|swf|css|js|woff|woff2|ttf|svg)$\">
        Header set Cache-Control \"max-age=31536000, public\"
    </FilesMatch>
</IfModule>
# END SPEEDBOOSTER CACHE HEADERS
";

        $content = file_get_contents($htaccess);

        if (strpos($content, 'SPEEDBOOSTER CACHE HEADERS') === false) {
            file_put_contents($htaccess, $content."\n".$rules);
        }

        return true;
    }
}

Ta wersja php mam za zadanie poprawić:

Ustawienia PrestaShop – CCC, cache Smarty, kompresja HTML/JS/CSS.

.htaccess – automatycznie dopisuje nagłówki Expires i Cache-Control.

Grafika trzymana w cache 1 rok

CSS/JS 1 miesiąc

Domyślne pliki 7 dni

Testujcie:  )

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...