Dynamic update sitemap.xml when DB collection updated
Is sitemap change, if db collection changed (which use to sitemap)? For example, is sitemap update, if WikiPages was updated?
sitemaps.add('/mw_AllPages_sitemap.xml.gz', function(req) { var out = [], pages = WikiPages.find().fetch(); _.each(pages, function(page) { out.push({ page: 'read/' + page.name, lastmod: page.lastUpdated }); }); return out; });
Yes, that's right. The function(req) {...} is called, and the sitemap generated, at request time. As such the provided sitemap is always "up-to-date" w.r.t. the database.
Is this function function(req) {...} called once? I created the file sitemap.js according to the instructions and once call sitemaps.add(). Is a sitemap reactively updated or only if I called sitemaps.add() again?
You only need to call sitemaps.add() once. function(req) {...} is called every time a request is made to the sitemap url, and returns the information from that call.
It's not quite right to say that it's updated "reactively" but it has the same effect. It's not "reactive" because nothing runs as soon as you change the data. Rather, the data is requested on every request, so it's always "up-to-date".
You only need to call
sitemaps.add()once.function(req) {...}is called every time a request is made to the sitemapurl, and returns the information from that call.It's not quite right to say that it's updated "reactively" but it has the same effect. It's not "reactive" because nothing runs as soon as you change the data. Rather, the data is requested on every request, so it's always "up-to-date".
Thank you, I'm understand
This is enough for search engines?Maybe I need regularly to do request to sitemap.xml to update it?
Yup, it was created specifically for the search engines. How often it's checked depends on the individual search engine. The engines will continuously monitor your sitemaps on their own without any further action on your part, possibly influenced by the changefreq parameter for each page.
While it is usually possible to manually request a recheck by the search engine, this is usually only necessary to urgently correct big mistakes (or after adding your sitemap for the first time).