Sub topic 10
Using lastmod honestly, and fields crawlers ignore
This chapter assumes you can read basic XML and know how URLs and HTTP status codes work. It also assumes you have seen the sitemap structure from the previous chapter: a urlset element holding url elements, each with a loc. Here the focus is on the optional fields that sit next to loc. One of them, lastmod, is useful when you maintain it carefully. The other two, priority and changefreq, are ignored by Google.
What the optional fields are for
The sitemap protocol defines four child elements of url:
| Element | Required | What it says | Practical status |
|---|---|---|---|
| `loc` | Yes | The absolute URL of the page | Used |
| `lastmod` | No | When the page was last meaningfully modified | Used when it proves reliable |
| `changefreq` | No | A hint about how often the page changes | Ignored by Google |
| `priority` | No | A relative importance from 0.0 to 1.0 | Ignored by Google |
Crawlers have limited time for each site. A sitemap can help them choose which URLs to revisit first. That only works if the hints are accurate. A signal that is often wrong gets discounted, and a signal that is never useful gets dropped. The history of these three fields shows both outcomes.
What lastmod means
lastmod records the date a page last changed in a way a reader would care about. A crawler that sees a lastmod later than its last visit has a reason to refetch the page. A crawler that sees an unchanged lastmod can spend that visit elsewhere.
The value must be in W3C Datetime format, which is a profile of ISO 8601. You can use a date alone or a full timestamp with a time zone:
2026-11-012026-10-15T09:30:00+00:002026-10-15T09:30:00Z
Both forms are valid. A date is enough for most sites. Use a full timestamp when a page changes several times a day, such as a news feed.
Common formatting errors
Most lastmod problems are formatting mistakes that make the value unparseable. Watch for these:
- Dates written as
11/01/2026or1 Nov 2026. These are not W3C Datetime. - A timestamp with no time zone, such as
2026-10-15T09:30:00. IncludeZor an offset so the time is unambiguous. - Timestamps in the future. A page cannot have been modified tomorrow.
- A literal placeholder such as
0000-00-00coming from an empty database column.
A parser that cannot read the value will usually ignore it. Worse, it may count it against the reliability of the whole file.
Using lastmod honestly
The word "honestly" matters here. Google has said it uses lastmod only when the value is consistently and verifiably accurate. If it checks a sample of your pages and finds that lastmod often disagrees with the real content, it stops trusting the field for your site. After that, even correct values are not used.
The rule is simple to state: set lastmod to the time of the last significant change to the page content, and never to anything else.
What counts as a significant change
Changes that justify updating lastmod:
- The main text, images, or structured data changed.
- A price, a stock status, or an event date changed.
- A key link in the main content was added or removed.
Changes that do not:
- A new copyright year in the footer.
- A refreshed sidebar, ad slot, or "related posts" widget.
- A changed comment count or view counter.
- A new CSRF token or any other value that differs on each request.
- A site-wide template change that touched every page's markup but not its content.
Typical ways sites get this wrong
The most common mistake is stamping every URL with the time the sitemap was generated. If a nightly job runs at 02:00 and writes 2026-11-30T02:00:00Z for all 40,000 URLs, then every URL appears to have changed every night. Within a few crawls a search engine learns that the field carries no information.
The second mistake is using the file system's modified time of a template, or a database updated_at column that a background job touches whenever it recalculates a cache. Neither one reflects a content change.
The third mistake is leaving lastmod stuck at the publish date after real edits. That causes the opposite problem: the crawler sees no change and may skip a page that deserves a refetch.
A reliable source of truth
Store a dedicated content-modified timestamp that your publishing workflow sets only when an editor saves a real change. Then have the sitemap generator read that column. In a static site, a content hash works well. Record the hash with each build, and move lastmod forward only when the hash changes.
import hashlib
import json
from datetime import datetime, timezone
from pathlib import Path
STATE_FILE = Path("lastmod-state.json")
def load_state():
if STATE_FILE.exists():
return json.loads(STATE_FILE.read_text(encoding="utf-8"))
return {}
def update_lastmod(pages):
"""pages maps a URL to its main content as a string.
Returns a dict mapping each URL to its lastmod value. The value only
changes when the content hash changes.
"""
state = load_state()
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S+00:00")
result = {}
for url, content in pages.items():
digest = hashlib.sha256(content.encode("utf-8")).hexdigest()
previous = state.get(url)
if previous is None or previous["hash"] != digest:
state[url] = {"hash": digest, "lastmod": now}
result[url] = state[url]["lastmod"]
STATE_FILE.write_text(json.dumps(state, indent=2), encoding="utf-8")
return result
if __name__ == "__main__":
sample = {
"https://www.example.com/": "Welcome to the home page.",
"https://www.example.com/about": "About our company.",
}
for url, lastmod in update_lastmod(sample).items():
print(url, lastmod)Run it twice. The second run prints the same timestamps, because nothing changed. Edit one string and run it again. Only that URL moves forward. Hash only the main content, not the full HTML, or a changing footer will defeat the purpose.
Fields crawlers ignore: changefreq and priority
changefreq
changefreq accepts one of always, hourly, daily, weekly, monthly, yearly, or never. The protocol describes it as a hint, not a command. Google states that it ignores the value. The reason is practical: site owners set it by guess or by habit, and the claimed frequency rarely matched how often the page changed. A real signal (lastmod, plus what the crawler observes on its own visits) replaced it.
priority
priority takes a number from 0.0 to 1.0, with a default of 0.5. It was meant to say which of your own pages matter most. Google ignores it too. In practice, many sites set 1.0 on everything, which cancels the meaning, since the value is only relative within one site. It never affected how your pages rank against other sites' pages.
What to do with them
Leave both out. Omitting them is valid, makes the file smaller, and removes a source of inconsistency to maintain. Including them does no harm to validity, so there is no need to strip them from an old file urgently. Some other crawlers or tools may still read them, but you should not rely on that.
Compare a minimal entry with an old-style entry:
<url>
<loc>https://www.example.com/blog/first-post</loc>
<lastmod>2026-10-15T09:30:00+00:00</lastmod>
</url>
<url>
<loc>https://www.example.com/blog/first-post</loc>
<lastmod>2026-10-15T09:30:00+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>Search engines treat these two entries the same way.
The lastmod on a sitemap index
A sitemap index file can also carry lastmod for each child sitemap. The same rule applies: it should be the latest lastmod of any URL inside that child file, not the time the file was regenerated. Tying the two together gives a crawler a cheap way to skip an entire child sitemap when nothing in it changed.
def index_lastmod(child_lastmods):
"""Return the newest lastmod from a list of W3C Datetime strings.
All values must use the same format and offset style for string
comparison to give the correct answer.
"""
return max(child_lastmods)
print(index_lastmod(["2026-11-01", "2026-11-20", "2026-10-02"]))This prints 2026-11-20. String comparison is safe here because W3C Datetime values in the same format sort in time order. If you mix dates, offsets, and Z, parse them into datetime objects first.
Checking that your lastmod is trustworthy
Run a quick audit before you rely on the field:
- Count the distinct
lastmodvalues in the file. If a large site has only one or two, the values are probably a build timestamp. - Pick ten pages at random and compare each
lastmodwith the page's real edit history. - Look for values in the future or before the site existed.
- Confirm that unchanged pages keep the same value from one build to the next.
import xml.etree.ElementTree as ET
from collections import Counter
NS = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
def audit(path):
tree = ET.parse(path)
values = [
el.text.strip()
for el in tree.getroot().findall("sm:url/sm:lastmod", NS)
if el.text
]
counts = Counter(values)
print(f"{len(values)} lastmod values, {len(counts)} distinct")
for value, n in counts.most_common(3):
print(f" {value}: {n} URLs")
audit("sitemap.xml")If the output shows 40,000 values and one distinct entry, the file is stamped with the build time and needs fixing.
Summary of decisions
| Question | Answer |
|---|---|
| Should I include `lastmod`? | Yes, if you can keep it accurate. Otherwise omit it. |
| What should it equal? | The time of the last significant content change. |
| Should I include `changefreq` or `priority`? | No. Google ignores them. |
| Is a missing `lastmod` a problem? | No. It is optional, and a missing value is better than a wrong one. |
Exercise
A nightly job regenerates your sitemap and writes the current time as lastmod for every URL. Search Console shows pages you edited last week are not being recrawled any faster than before. Explain why, and describe the fix.
Show answer
Because every URL gets a new lastmod each night, the value no longer separates changed pages from unchanged ones, so the search engine learns to ignore the field for the site. The fix is to store a content-modified timestamp that is updated only when the main content changes (for example, by comparing a content hash between builds), have the generator write that value, and leave it unchanged for pages that did not change. If no reliable timestamp can be produced, omit lastmod.
Exercise
Is a sitemap that contains changefreq daily and priority 1.0 on every URL invalid? Does it help crawling on Google?
Show answer
It is valid, because both elements are optional and allowed by the protocol. It does not help on Google, which ignores both fields. Setting priority to 1.0 on every URL also removes any meaning the value had, since priority is only relative within a site. Remove them to keep the file simple.