Jump to content

[Need Prestashop 1.6][Fixed Prestashop 1.7]How to add version to all css and js Files


Adrian

Recommended Posts

Dear Community,

 

At this moment im trying to implement on my shop (PRESTASHOP 1.6.1.17) a modification that adds to the css files a version so I can ensure that the client is going to reload the page with the latest version:

 

The result that I would like is something like

<link rel="stylesheet" href="/url_path/mystyles.css?v=123" type="text/css" media="all" />

 

I have been searching for a solution and I found a thread from 2011 and updated last year, but i'm not able to run it correctly.

Thread: https://www.prestashop.com/forums/topic/136126-auto-versioning-css-files-force-css-refresh/

(I tried creating an override with the last comment of this thread and it don't seem to work).

 

I hope someone can help me or at least give me the idea of how to do it.

 

Thanks in advance.

Edited by Adrian (see edit history)
Link to comment
Share on other sites

fixed it: 

add to /override/classes/assets/StylesheetManager.php

<?php
class StylesheetManager extends StylesheetManagerCore
{
    protected function add($id, $fullPath, $media, $priority, $inline, $server)
    {
        if ('local' === $server && !$inline) {
            if (file_exists($_SERVER['DOCUMENT_ROOT'] . $fullPath)) {
                $version = filemtime($_SERVER['DOCUMENT_ROOT'] . $fullPath);
            } else {
                $version = '1';
            }

            $fullPath = $fullPath . '?v=' . $version;
        }

        parent::add($id, $fullPath, $media, $priority, $inline, $server);
    }
}

 

Edited by sharkooon (see edit history)
Link to comment
Share on other sites

13 hours ago, sharkooon said:

fixed it: 

add to /override/classes/assets/StylesheetManager.php


<?php
class StylesheetManager extends StylesheetManagerCore
{
    protected function add($id, $fullPath, $media, $priority, $inline, $server)
    {
        if ('local' === $server && !$inline) {
            if (file_exists($_SERVER['DOCUMENT_ROOT'] . $fullPath)) {
                $version = filemtime($_SERVER['DOCUMENT_ROOT'] . $fullPath);
            } else {
                $version = '1';
            }

            $fullPath = $fullPath . '?v=' . $version;
        }

        parent::add($id, $fullPath, $media, $priority, $inline, $server);
    }
}

 

 

Thank you for your help but in Prestashop 1.6 I do not find the class StylesheetManager, searching on Google it seems to be for Prestashop 1.7 . Thank you anyway

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
  • 6 months later...

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...