问题
Fellow Meteor users,
During my searches for tutorials and example applications, I found one that uses a unique head structure:
<meta charset="utf-8">
<title>Title</title>
<meta name="description" content="Top10">
<meta name="viewport" content="width=device-width" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1">
This particular example app didn't even have a <body> tag anywhere, just a file called head.html which contained the above code. I also learned that it seems that Meteor just automatically makes a body tag for you, so technically, just a head.html is fine.
So, it got me wondering, does anyone define specific head tags for Meteor apps? What's the rationale? Is the above code a good starting point?
回答1:
You can easily set dynamic titles using iron:router for example with:
onAfterAction: function(){
document.title = 'my awesome site: ' + Router.current().route.getName();
}
I use a head.html that includes various SEO settings:
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="fragment" content="!"/>
<meta name="description" content="your description"/>
<meta property="og:title" content="your site title"/>
<meta property="og:type" content="website"/>
<meta property="og:image" content="https://yourimageurl"/>
<meta property="og:url" content="https://hostname"/>
<meta property="og:description" content="your description"/>
<meta name="twitter:card" content="summary"/>
<meta name="twitter:url" content="https://hostname"/>
<meta name="twitter:title" content="your site title"/>
<meta name="twitter:description" content="your site description"/>
<meta name="twitter:image" content="https://yourimageurl">
<noscript>You must have Javascript enabled in order to use this site</noscript>
<link rel="shortcut icon" href="/your-ico" type="image/x-icon" />
</head>
回答2:
When Meteor parses your various html files, any files that contain a <head></head> tag outside of a <template></template> will be concatenated together into one <head></head> tag in every page of your app. This is good for including stuff like title, various meta tags, and 3rd party resources that you want to use on every page. However handlebars support for title tags still does not exist in Meteor so it is definitely limited in what you can do with it (No dynamic meta information).
In the end if you want dynamic information you'll have to resort to something like jquery
You can find more discussion revolving around the <head> tag here:
https://github.com/meteor/meteor/issues/266
回答3:
Looking into https://github.com/kadirahq/meteor-dochead I found one way to dynamically add data to <head> tag
var meta = '<div>just an example</div>'
document.getElementsByTagName('head')[0].insertAdjacentHTML('beforeend', meta);
Or just add that package if you need more functionality
来源:https://stackoverflow.com/questions/29972319/suggestions-for-head-tags-for-meteor