我目前在使用 Cordova 生成 .apk 文件时遇到应用程序性能非常低的问题。
这对我来说很奇怪,因为当我在预构建阶段在 PC 网络浏览器上运行 HTML 文件时,性能非常流畅且快速。
这不是模拟器的问题,因为我在用于测试的手机上遇到了类似的行为。
我怀疑这可能与我的 index.html 文件中的脚本数量有关,但我不确定。
这是头
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bower_components\bootstrap\dist\css\bootstrap.min.css">
<link rel="stylesheet" href="css/boton.css">
<script src="bower_components\jquery\dist\jquery.min.js"></script>
<script src="bower_components\bootstrap\dist\js\bootstrap.min.js"></script>
<!-- Virtual tour -->
<script src="tour/dist/webtour.min.js"></script>
<script>
<!-- Webtour run once when web/application is open for the first time -->
</script>
<link rel="stylesheet" href="tour/dist/webtour.min.css" />
<style>
<!-- Styles defined here -->
</style>
<script>
<!-- Other scripts of mine. Run when needed. Sometimes on load, sometimes on clic -->
</script>
<script>
</script>
<script>
</script>
<script>
</script>
...
</head>
这是尸体
<body onload="iniciarTour();numeroTotalDeCanciones();">
<!-- Estas son las instrucciones para los banners -->
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<div class="app" style="display:none;">
<div id="deviceready" class="blink">
<p class="event listening"></p>
<p class="event received"></p>
</div>
</div>
<div id="fullpage">
<!-- long app content in html -->
</div>
你有没有发现什么奇怪的地方?
我还必须将此行添加到 config.xml 文件中,以使其加载:
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Whatever</name>
<description>Sample Apache Cordova App</description>
<author email="[email protected]" href="https://cordova.apache.org">
Apache Cordova Team
</author>
<content src="index.html" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<preference name="SplashScreenDelay" value="10000" /> <!-- Added to prevent app to get stucked on the splash screen -->
<preference name="loadUrlTimeoutValue" value="700000" /> <!-- Added to avoid the error: The connection to the server was unsuccessful. (file:///android_asset/www/index.html) -->
</widget>
您知道哪些功能可能无法正常工作吗?
谢谢!
问题是我在内容上包含了大量 iframe,导致加载非常耗时。
为了避免这种情况发生,我将所有 iframe src 修改为“about:blank”
然后,我修改每个 iframe 的 src 值iframe 根据用户需求,仅在用户请求或要与其交互时显示其内容。