Blog

How to spot changed URLs in long HTML fragments

Compare two long HTML fragments by extracting their URL values first, then spot changed, added, and removed links without getting distracted by markup.

Sarah CollinsTools and utilities 5 min read

Two HTML fragments can look almost identical while one link points somewhere different. Comparing the full text often makes it harder to notice: tags, line breaks, and unrelated edits bury the URL change.

Instead, make a list of the URL values in each fragment, then compare those lists. This makes changed, added, and removed addresses easier to spot, while keeping enough nearby context to confirm what each link belongs to.

Compare the URLs

  1. Keep separate copies. Save the original fragments as “Old” and “New” in a text editor. Do not edit either source while comparing. If you have a text comparison tool, you can use it later on the extracted URL lists rather than on the full HTML.
  2. Decide which URL fields matter. For ordinary links, look for href=. If you also need addresses for images or embedded content, check src=. Forms can use action=, and video elements can use poster=. Include only the fields relevant to your check.
  3. Find each value in both fragments. Use your editor’s Find feature to search for the attribute name, such as href=. Copy the complete value between its quotation marks into a separate list, one value per line. Keep a short label beside it, such as nearby link text or the element name, so you can identify where it appeared.
  4. Keep duplicate entries. If the same URL appears in three places, list it three times. Removing duplicates can hide a change where one link was removed and another copy was added elsewhere. Keep the original order too, at least until you have matched each entry to its context.
  5. Compare the lists and label each difference. Match entries by their nearby text or HTML element. Mark a changed value as changed, a value present only in the new fragment as added, and one present only in the old fragment as removed. If the order changed but the same links remain in the same contexts, record it as a move rather than a URL change.

A useful note might read: “The link labeled Account changed from /account to /members/account.” That is more actionable than saying the HTML differs somewhere in a long block.

What the result means

The hostname or path changed

Check that the destination is expected. A new hostname can send visitors to a different site, and a small path change can lead to a different page or a missing page. Compare the whole address, including whether it starts with http:// or https://.

Only the query string changed

The query string begins after a question mark, as in ?item=12. It may carry a search term, product choice, tracking value, or other instruction. Do not assume a changed parameter is harmless. Check the page’s intended behavior, and compare the parameter names and values.

The same address appears, but in a different place

This may be a reordered link rather than a changed destination. Match the URL to its nearby anchor text, image, or form before calling it a change. For repeated identical URLs, use the element’s position or surrounding text to distinguish each occurrence.

The source shows & in one address

In HTML source, an ampersand in an attribute may be written as the character reference &. When read as HTML, that represents an ordinary ampersand in the URL. Compare the actual attribute values, and do not mistake this required source encoding for an extra URL parameter.

A relative address looks different

An address such as images/logo.png depends on the page’s base address, while /images/logo.png starts at the site root. They are not interchangeable in every location. Keep the page URL or any <base> element in mind when deciding whether two relative addresses lead to the same place.

Check suspicious differences

  1. Compare punctuation exactly. Check for a missing slash, a changed hyphen, an extra question mark, or a different fragment after #. These small edits can change the destination.
  2. Do not treat case as automatically harmless. Hostnames are not case-sensitive, but paths on a website can be. Keep the original capitalization until you confirm how the destination handles it.
  3. Check query parameters in order and context. Two URLs may contain the same parameter names in a different order, but a site can treat repeated parameters or their order differently. Compare the full string before deciding the change has no effect.
  4. Check encoded characters carefully. A space, slash, or other character may appear as a percent-encoded value such as %20. Do not decode and replace values just to make them look simpler. Keep the exact source value in your notes.
  5. Look beyond links if needed. URLs may also appear in CSS as url(...), in a script, or in a data attribute. Searching only for href= will not find those. Add the relevant fields to your check if the change could affect them.
  6. Confirm the intended destination. When a change matters, open the new address in a separate browser tab if it is safe to do so. Check that it reaches the expected page before updating or approving the HTML.

Why comparing the whole fragment can mislead you

HTML can differ for reasons that do not change a URL. An editor may wrap a long line, reorder attributes, or change spacing between tags. A text comparison tool will flag those edits along with address changes, so treat its highlights as clues rather than proof that a link changed.

Also keep the raw value and its context together. A URL without its link text may be hard to identify later, especially when the same address is used repeatedly. A short record with the old value, new value, and nearby label is usually enough to review the change or explain it to someone else.

If the fragments contain private or unpublished information, compare them in a local editor rather than pasting them into an online service you do not trust.