diff options
author | Freya Murphy <freya@freyacat.org> | 2024-03-30 21:28:46 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-03-30 21:28:46 -0400 |
commit | ef7b0e26fadb882e026f1b447b6d18259057c040 (patch) | |
tree | f5831c9c64b3fd95d8fa73b382d1717e10370684 /web/_model | |
parent | post comments, refactor post loading, hide load more btn (diff) | |
download | xssbook2-ef7b0e26fadb882e026f1b447b6d18259057c040.tar.gz xssbook2-ef7b0e26fadb882e026f1b447b6d18259057c040.tar.bz2 xssbook2-ef7b0e26fadb882e026f1b447b6d18259057c040.zip |
refactor asset dir, refactor oberver in lib
Diffstat (limited to 'web/_model')
-rw-r--r-- | web/_model/main.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/web/_model/main.php b/web/_model/main.php index f72a2f3..ab964fd 100644 --- a/web/_model/main.php +++ b/web/_model/main.php @@ -48,11 +48,22 @@ class Main_model { } /** + * Gets the stamp for a asset path + * @param string $path + */ + private function asset_stamp($path): int { + $root = $GLOBALS['webroot']; + $path = $root . '/public/' . $path; + return filemtime($path); + } + + /** * Loads a css html link * @param string $path - the path to the css file */ public function link_css($path) { - return '<link rel="stylesheet" href="/public/' . $path . '">'; + $stamp = $this->asset_stamp($path); + return '<link rel="stylesheet" href="/public/' . $path . '?stamp=' . $stamp . '">'; } /** @@ -60,7 +71,8 @@ class Main_model { * @param string $path - the path to the js file */ public function link_js($path) { - return '<script src="/public/'. $path . '"></script>'; + $stamp = $this->asset_stamp($path); + return '<script src="/public/'. $path . '?stamp=' . $stamp . '"></script>'; } /** |