2

In order to refresh my client browser with the last styles, I want to change the name of the generated files when I merge them.

What... where that name is generated?

I merge the css with System > Configuration > Developer > Css Settings > Merge CSS Files to Yes.

It generate a css like 9128734598173458912.css, but it's always the same name, and I want to change it each time I merge the css even the content doesn't change.

UPDATE

@xMageStore give me a good clue, but I think my solution is

Mage/Code/Model/Design/Package.php public function getMergedCssUrl($files){...}

Maybe @xMageStore solution is better to add a variable after each file, like styles.css?version=1.1 It's a good way to refresh the client browser

I need to check more to find what's the best solution

4
  • Magento 1.9 doesn't have a dedicated way that you can merge styles built into the framework, can you explain your set up in more detail? are you using a css pre-processor like sass or less? What theme are you using? Is it a custom theme, one of the built in themes or something that has been purchased?
    – circlesix
    May 17, 2018 at 13:09
  • If you clear the CSS/JS Cache, the files will have an update to the Last Modified Header Which will force browsers to re-download them & I think that accomplishes your goal.
    – mtr.web
    May 17, 2018 at 13:19
  • 1
    @circlesix - I think the OP is referring to the config setting to Merge CSS Files..
    – mtr.web
    May 17, 2018 at 13:19
  • Good call, think you're right.
    – circlesix
    May 17, 2018 at 15:16

3 Answers 3

2

Finally I rewrite getMergedCssUrl method in Mage_Core_Model_Design_Package, to automatically generate new name each time the css change I used:

 // merge into target file
        $olderTimestamp = '';
        foreach ($files as $file) {
            if ($olderTimestamp < filemtime($file)) {
                $olderTimestamp = filemtime($file);
            }
        }
        $targetFilename = md5(implode(',', $files) . "|{$hostname}|{$port}|{$olderTimestamp}") . '.css';

But special metion to @xMageStore, because I think your answer can be usefull if the css or Js isn't merged.

1

@oootramas answer is very elegant, but I think it could be even further improved upon. Just do

$timestampString = '';
 foreach ($files as $file) {
     $timestampString .= filemtime($file);
 }
 $targetFilename = md5(implode(',', $files) . "|{$hostname}|{$port}|{$timestampString}") . '.css';

Above code will take into account the filemtime of every CSS file, instead of the filemtime of just the oldest file.

That way you get a different hash if you edit a newer CSS file, too.

0

There is way to change name of merge css/js files. You can see Mage_Page_Block_Html_Head file and function name is getCssJsHtml() Hope it will help you!

2
  • Good point, but I'm not sure it's what I'm looking for... not sure, yet
    – ooootramas
    May 17, 2018 at 14:04
  • This function is used for naming the merged css/js so you can add the custom name here for the css/js.
    – xMageStore
    May 18, 2018 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.