问题
I'm doing my first steps in this environment and am trying to figure out the best practices. My app includes several HTML pages:
Should I duplicate the whole HEAD part into all the HTML pages,
Or maybe some of it is only required in the initial HTML page?
EXTRA
To my wonder I couldn't find an up-to-date example of a standard HTML header for such app, so with my question I'm also doing a share of knowledge.
Here is the header which, in my understanding, is required to allow the combination of JQM into PhoneGap:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self' gap://ready file://* *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; media-src *">
<title>JQM Test</title>
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" />
<!-- extra css for my app: -->
<link rel="stylesheet" type="text/css" href="css/index.css" />
<!-- include JQ, enable PhoneGap events under JQM, then include JQM: -->
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
$( document ).on( "mobileinit", function() {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
$.mobile.phonegapNavigationEnabled = true;
});
</script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script>
</head>
Just for the completeness, in case you are wondering, the cordova part appears at the end of the page:
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
回答1:
Note: Please do not downvote if this answer is wrong, but instead add a note explaining why it is wrong, so that we can all learn.
Nobody responded so I will put my tentative answer which I still need to verify.
In a normal web app, headers must be repeated because the user can bookmark a non-initial page, and get back to it later, so every page must be able to take the role of the initial page.
However with PhoneGap/Cordova we can ensure a specific page is loaded on startup, and this way, because pages are loaded using ajax, we might be able to skip the include parts of the other pages.
来源:https://stackoverflow.com/questions/41654004/phonegap-cordova-jquerymobile-should-head-be-repeated-in-all-pages