mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
perf: 优化预加载文件
This commit is contained in:
parent
d00cd5cb26
commit
cfb653796c
@ -1322,21 +1322,35 @@ class SystemController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function prefetch()
|
public function prefetch()
|
||||||
{
|
{
|
||||||
$file = base_path('.prefetch');
|
$userAgent = strtolower(Request::server('HTTP_USER_AGENT'));
|
||||||
if (!file_exists($file)) {
|
$isMain = str_contains($userAgent, 'maintaskwindow');
|
||||||
return [];
|
$isApp = str_contains($userAgent, 'kuaifan_eeui');
|
||||||
|
$version = Base::getVersion();
|
||||||
|
$array = [];
|
||||||
|
|
||||||
|
if ($isMain || $isApp) {
|
||||||
|
$path = 'js/build/';
|
||||||
|
$list = Base::readDir(public_path($path), false);
|
||||||
|
foreach ($list as $item) {
|
||||||
|
if (is_file($item) && filesize($item) > 50 * 1024) {
|
||||||
|
$array[] = $path . basename($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$version = Base::getVersion();
|
if ($isMain) {
|
||||||
|
$file = base_path('.prefetch');
|
||||||
|
if (file_exists($file)) {
|
||||||
$content = file_get_contents($file);
|
$content = file_get_contents($file);
|
||||||
|
$items = explode("\n", $content);
|
||||||
$array = explode("\n", $content);
|
$array = array_merge($array, $items);
|
||||||
$array = array_values(array_filter($array));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return array_map(function($item) use ($version) {
|
return array_map(function($item) use ($version) {
|
||||||
$url = trim($item);
|
$url = trim($item);
|
||||||
$url = str_replace('{version}', $version, $url);
|
$url = str_replace('{version}', $version, $url);
|
||||||
return url($url);
|
return url($url);
|
||||||
}, $array);
|
}, array_values(array_filter($array)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,9 +125,6 @@ export default {
|
|||||||
if (this.$Electron && $A.$isSubElectron) {
|
if (this.$Electron && $A.$isSubElectron) {
|
||||||
return; // 客户端子窗口 不预加载
|
return; // 客户端子窗口 不预加载
|
||||||
}
|
}
|
||||||
if (this.$isEEUiApp) {
|
|
||||||
return; // 移动端 不预加载
|
|
||||||
}
|
|
||||||
axios.get($A.apiUrl('system/prefetch')).then(({status, data}) => {
|
axios.get($A.apiUrl('system/prefetch')).then(({status, data}) => {
|
||||||
if (status === 200) {
|
if (status === 200) {
|
||||||
data.forEach(url => {
|
data.forEach(url => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user