gohhan
gohhan

Hi how you can get the latest file change and deduce the URL of the file: <link href="style.css?v=00000" rel="stylesheet">

aidonline01
aidonline01

Hi, I don't quite understand what do you mean, can you please clarify your question in other words?

mjauvin
mjauvin

@gohhan, it's feasible but I don't suggest it because it slows down your request even more when checking the file timestamp on disk... what I usually do is this:

<link rel="stylesheet" href="{{ 'assets/css/style.css' | theme ~ '?v=1.0.1' }}">

And I manually increment the version number when the file changes.

But if you REALLY want the code to check this automatically everytime, I can suggest a way to do this, just let me know.

gohhan
gohhan

mjauvin said:

@gohhan, it's feasible but I don't suggest it because it slows down your request even more when checking the file timestamp on disk... what I usually do is this:

<link rel="stylesheet" href="{{ 'assets/css/style.css' | theme ~ '?v=1.0.1' }}">

And I manually increment the version number when the file changes.

But if you REALLY want the code to check this automatically everytime, I can suggest a way to do this, just let me know.

What about cashing? Will you turn to the file every time you load the page? I'd be happy if you send the code. There are projects that often have changes and it is not always convenient to manually change the version of the file.

Last updated

mjauvin
mjauvin

Here's one way to do this.

In your layout, replicate the example below:

description = default layout
==
function onInit()
{
    $styleAsset = 'assets/css/style.css';
    $lastUpdate = filemtime($this->theme->getPath() . '/' . $styleAsset);
    $this['stylesheet'] = sprintf('%s?v=%s', $this->controller->themeUrl($styleAsset), $lastUpdate);
}
==
...
<link rel="stylesheet" href="{{ stylesheet }}">
...
gohhan
gohhan

mjauvin said:

Here's one way to do this.

In your layout, replicate the example below:

description = default layout
==
function onInit()
{
   $styleAsset = 'assets/css/style.css';
   $lastUpdate = filemtime($this->theme->getPath() . '/' . $styleAsset);
   $this['stylesheet'] = sprintf('%s?v=%s', $this->controller->themeUrl($styleAsset), $lastUpdate);
}
==
...
<link rel="stylesheet" href="{{ stylesheet }}">
...

Thank you! It's working!

mjauvin
mjauvin

Of course it's working!

Last updated

gohhan
gohhan

Hello, I noticed one feature. Function onInit does not work in partials, only in layouts.

mjauvin

1-9 of 9