Instead of updating the same variable in various locations I parse files and extract the bits I need. One bit I am looking for is the cache name in my service-worker.js file. When I'm developing locally, I can easily retrieve the js file in the directory structure.
When I deploy my app to GAE, the service worker JS file needs to be declared static and so GAE stashes it away somewhere.
Is there a way to get to this file without making a URL call?
This is what I currently use and it's all working fine in DEV:
<?php
function getCacheId() {
$cache_id = "";
$c = file_get_contents ( dirname ( __FILE__ ) . "/service-worker.js" );
if (preg_match ( "/CACHE_NAME = '(.*)'/", $c, $matches ) !== false) {
if (count ( $matches )) {
$cache_id = trim ( $matches[1] );
}
}
return $cache_id;
}
?>
<script>
const CACHEID = "<?php echo getCacheId() ?>";
</script>
You need to also configure
application_readable: true
in addition to the static file declaration in yourapp.yaml
file.From Handlers element: