所以我正在尝试设置 prerender.io对于我的带有 ExpressJS 后端的 AngularJS 应用程序,遵循此 tutorial .我完全按照指示做了,唯一的区别是我启用了 HTML5mode
.我已经包含了 meta(name="fragment" content="!")
在我的 index.jade
和我的 server.js
的预呈现 token 文件(使用 prerender-node 包),但不知何故我的页面似乎没有被缓存或生成任何抓取统计信息。
config.coffee
angular.config ['$stateProvider','$urlRouterProvider','$locationProvider','toastrConfig',($stateProvider, $urlRouterProvider,$locationProvider,toastrConfig)->
$stateProvider
.state 'home',
url:'/'
templateUrl: 'html/main.html'
controller:'mainController'
$urlRouterProvider.otherwise '/'
$locationProvider.html5Mode
enabled: true
requireBase: false
$locationProvider.hashPrefix '!'
]
Server.JS
// Here we require the prerender middleware that will handle requests from Search Engine crawlers
// We set the token only if we're using the Prerender.io service
app.use(require('prerender-node')
.set('prerenderServiceUrl', 'http://www.mydomain.co.com/')
.set('prerenderToken', 'my-token'));
// HTML5MODE settings
// ------------------------------------------------------
app.use('/js', express.static(__dirname + '/public/js'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/html', express.static(__dirname + '/public/html'));
// Routes
// ------------------------------------------------------
require('./app/js/routes/routes.js')(app);
app.all('/*', function(req, res, next) {
// Just send the index.html for other files to support HTML5Mode
res.sendFile('/public/index.html', { root: __dirname });
});
最佳答案
你应该从你的配置中删除这一行:
.set('prerenderServiceUrl', 'http://www.mydomain.co.com/')
服务 URL 应指向 Prerender 服务器,因此您不应将其设置为您的网站 URL。
关于angularjs - Prerender.io 不缓存我的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37319412/