fix:优化项目加载
This commit is contained in:
7
build.js
7
build.js
@@ -2,6 +2,7 @@
|
||||
/**
|
||||
* 将静态资源复制到 dist/,便于直接部署到任意静态主机。
|
||||
* 产出: dist/index.html, dist/config.json, dist/lib/, dist/image/
|
||||
* 构建时注入 __CACHE_VERSION__ 为时间戳,用于防微信/浏览器强缓存,保证发版后页面可更新。
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
@@ -56,7 +57,11 @@ function main() {
|
||||
}
|
||||
fs.mkdirSync(DIST, { recursive: true });
|
||||
|
||||
copyFile(path.join(ROOT, 'index.html'), path.join(DIST, 'index.html'));
|
||||
const cacheVersion = String(Date.now());
|
||||
let indexHtml = fs.readFileSync(path.join(ROOT, 'index.html'), 'utf8');
|
||||
indexHtml = indexHtml.replace(/__CACHE_VERSION__/g, cacheVersion);
|
||||
fs.writeFileSync(path.join(DIST, 'index.html'), indexHtml, 'utf8');
|
||||
|
||||
copyFile(path.join(ROOT, 'config.json'), path.join(DIST, 'config.json'));
|
||||
copyFile(path.join(ROOT, 'api.config.json'), path.join(DIST, 'api.config.json'));
|
||||
copyDir(path.join(ROOT, 'lib'), path.join(DIST, 'lib'));
|
||||
|
||||
12
index.html
12
index.html
@@ -4,8 +4,12 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
||||
<meta http-equiv="Pragma" content="no-cache">
|
||||
<meta http-equiv="Expires" content="0">
|
||||
<title>全景查看</title>
|
||||
<link rel="stylesheet" href="lib/pannellum.css">
|
||||
<script>window.__CACHE_VERSION__='__CACHE_VERSION__';</script>
|
||||
<link rel="stylesheet" href="lib/pannellum.css?v=__CACHE_VERSION__">
|
||||
<style>
|
||||
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
|
||||
.pano-root { flex: 1 1 0%; position: relative; width: 100%; height: 100%; }
|
||||
@@ -207,7 +211,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="lib/pannellum.js"></script>
|
||||
<script src="lib/pannellum.js?v=__CACHE_VERSION__"></script>
|
||||
<script>
|
||||
(function() {
|
||||
var API = '/api';
|
||||
@@ -443,7 +447,7 @@
|
||||
|
||||
function loadFromConfig(cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'config.json', true);
|
||||
xhr.open('GET', 'config.json?v=' + (window.__CACHE_VERSION__ || ''), true);
|
||||
xhr.onload = function() {
|
||||
if (xhr.status !== 200) { if (cb) cb(null); return; }
|
||||
var config;
|
||||
@@ -479,7 +483,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
fetch('api.config.json')
|
||||
fetch('api.config.json?v=' + (window.__CACHE_VERSION__ || ''))
|
||||
.then(function(r) {
|
||||
if (!r.ok) return Promise.resolve({ apiBase: '' });
|
||||
return typeof r.json === 'function' ? r.json().catch(function() { return { apiBase: '' }; }) : Promise.resolve({ apiBase: '' });
|
||||
|
||||
Reference in New Issue
Block a user