mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-04-30 20:17:44 -05:00
The index.php file specifies a version query string for each
resource which is likely to change. For example:
<script src="/js/sim.js?v0.8.2c"></script>
Each time the file is changed, we have incremented the version
number so that browsers and/or the CDN know to download the
file from the web site, rather than using a cached version.
This works because changing the version query string changes
the file name of the resource.
This commit introduces a new program (update-version-query-strings)
which parses index.php and sets each version query string to be
the MD5 hash of the corresponding resource. On the live web
server, this program is set to run for the following git hooks:
post-commit, post-checkout, post-merge, post-rewrite
This new system removes the need to manually update version query
strings. Instead, the version query strings will be automatically
updated when we update the live web site from now on.
22 lines
637 B
PHP
Executable File
22 lines
637 B
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
/**
|
|
* This script parses index.php and sets the version query string of each
|
|
* resource to be the MD5 hash of that resource. This script should be executed
|
|
* from the base directory of the repository.
|
|
*
|
|
* On the live web server, this script is set as the following git hooks:
|
|
* post-commit, post-checkout, post-merge, post-rewrite
|
|
*/
|
|
|
|
define('SOURCE_FILE', 'index.php');
|
|
|
|
file_put_contents(SOURCE_FILE,
|
|
preg_replace_callback('/(src|href)="\/(.*?)\?[a-z0-9]*?"/',
|
|
function($m) {
|
|
$hash = md5_file($m[2]);
|
|
return "${m[1]}=\"/${m[2]}?${hash}\"";
|
|
},
|
|
file_get_contents(SOURCE_FILE)));
|
|
|