Commit: 14754366565fbb9ea116e8545c60537d98f13014 Author: Levi Morrison <[email protected]> Fri, 28 Mar 2014 12:46:16 -0600 Parents: 10e06f446e2c2081201121fc2bdd6f0ea6296e5d Branches: master
Link: http://git.php.net/?p=web/shared.git;a=commitdiff;h=14754366565fbb9ea116e8545c60537d98f13014 Log: Added filemtime parameter for caching certain assets. Changed paths: M templates/footer.inc M templates/header.inc Diff: diff --git a/templates/footer.inc b/templates/footer.inc index effad64..ebf98d4 100644 --- a/templates/footer.inc +++ b/templates/footer.inc @@ -1,4 +1,5 @@ <?php +$JS = array(); /** * Typical footer * @@ -11,6 +12,12 @@ isset($JS) || $JS = array(); isset($SECONDSCREEN) || $SECONDSCREEN = ""; $ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ? "//shared.php.net" : "/shared"; +$current_time = time(); +$scripts = array_merge($JS, array( + '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', + '/js/external/mousetrap.min.js', + '/js/common.js' +)); ?> <?php if ($SECONDSCREEN): ?> @@ -29,16 +36,16 @@ $ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ? "//shared.php.net" : </nav> </footer> -<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> -<script src="<?php echo $ROOT?>/js/external/mousetrap.min.js"></script> -<script src="<?php echo $ROOT?>/js/common.js"></script> -<?php foreach($JS as $script) :?> - <?php if (strncmp($script, "//", 2) == 0): ?> - <script src="<?php echo $script?>"></script> - <?php else: ?> - <script src="<?php echo $ROOT ?><?php echo $script?>"></script> - <?php endif ?> -<?php endforeach ?> +<?php +foreach ($scripts as $script) { + if (strncmp($script, "//", 2) == 0) { + echo "<script src='$script'></script>\n"; + } else { + $filemtime = filemtime(__DIR__ . "/..{$script}") ?: time(); + echo "<script src='{$ROOT}{$script}?filemtime=$filemtime'></script>\n"; + } +} +?> </body> </html> <?php /* vim: set ft=html et ts=2 sw=2: : */ ?> diff --git a/templates/header.inc b/templates/header.inc index 2ab72a1..6a96f71 100644 --- a/templates/header.inc +++ b/templates/header.inc @@ -26,6 +26,8 @@ isset($HEAD_RAND) || $HEAD_RAND = ""; isset($CSS) || $CSS = array(); isset($SEARCH) || $SEARCH = array(); $ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ? "//shared.php.net" : "/shared"; +$current_time = time(); +$default_css_mtime = filemtime(__DIR__ . '/../styles/defaults.css') ?: $current_time; ?> <!DOCTYPE html> <html> @@ -34,11 +36,15 @@ $ROOT = substr($_SERVER["SERVER_NAME"], -8) == ".php.net" ? "//shared.php.net" : <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>PHP: <?=$TITLE ?></title> - <link media="all" rel="stylesheet" href="<?php echo $ROOT?>/styles/defaults.css"> + <link media="all" rel="stylesheet" href="<?php echo "$ROOT/styles/defaults.css?filemtime=$default_css_mtime";?>"> -<?php foreach($CSS as $style): ?> - <link media="all" rel="stylesheet" href="<?php echo $ROOT?><?php echo $style?>"> -<?php endforeach ?> +<?php +foreach($CSS as $style): + // note that $style should have a leading slash + $filemtime = filemtime(__DIR__ . '/..' . $style) ?: $current_time; + echo " <link media='all' rel='stylesheet' href='{$ROOT}{$style}?filemtime=$filemtime'/>\n"; +endforeach +?> <link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,400italic,600italic|Source+Code+Pro&subset=latin,latin-ext" rel="stylesheet"> <link rel="shortcut icon" href="//php.net/favicon.ico"> -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
