<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Adam Smith: Writing</title><description>Short posts by Adam Smith on software engineering, .NET and data tooling.</description><link>https://cadamsmith.dev/writing/</link><language>en-us</language><atom:link href="https://cadamsmith.dev/writing/rss.xml" rel="self" type="application/rss+xml"/><item><title>What&apos;s inside a source map, and why you can&apos;t just glue two together</title><link>https://cadamsmith.dev/writing/concatenating-source-maps/</link><guid isPermaLink="true">https://cadamsmith.dev/writing/concatenating-source-maps/</guid><description>How the mappings string encodes positions with relative Base64 VLQ, why concatenating two maps sends devtools to the wrong file, and the two correct ways to combine them.</description><pubDate>Tue, 01 Dec 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A bundler minifies each file and joins the results. Joining the JavaScript is one line of code. Joining the source maps that came with it is the step that’s easiest to get subtly wrong. The bundle runs fine and devtools opens without complaint, but every breakpoint after the first file lands in the wrong place.&lt;/p&gt;
&lt;p&gt;To see why, you have to look inside a map.&lt;/p&gt;
&lt;h2 id=&quot;what-a-map-holds&quot;&gt;what a map holds&lt;/h2&gt;
&lt;p&gt;Take a small file and its minified output:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;a.js&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt; add&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;first&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; second&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;	return&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; first &lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; second&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;a.min.js&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt; add&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;	return&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;Its source map is a JSON file:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;a.min.js.map&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;file&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;a.min.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;sources&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;a.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;names&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;add&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;first&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;second&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;mappings&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;AAAA,SAASA,IAAIC,EAAOC,GAClB,OAAOD,EAAQC&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;sources&lt;/code&gt; lists the original files and &lt;code&gt;names&lt;/code&gt; lists original identifiers. Everything else is in &lt;code&gt;mappings&lt;/code&gt;, which links positions in the minified file to positions in the originals.&lt;/p&gt;
&lt;h2 id=&quot;reading-the-mappings-string&quot;&gt;reading the mappings string&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;mappings&lt;/code&gt; is split into lines by &lt;code&gt;;&lt;/code&gt;, one group per line of generated code. This file is one line, so there’s no &lt;code&gt;;&lt;/code&gt;. Each line is split by &lt;code&gt;,&lt;/code&gt; into segments, and each segment is a run of numbers:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;field&lt;/th&gt;
&lt;th&gt;meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;column in the generated line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;index into &lt;code&gt;sources&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;line in that source&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;column in that source&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;index into &lt;code&gt;names&lt;/code&gt; (optional, for a renamed symbol)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A segment has 1, 4 or 5 fields. A 1-field segment marks generated code that comes from no source. All positions are zero-based.&lt;/p&gt;
&lt;p&gt;Decoded, the map above says:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;segment&lt;/th&gt;
&lt;th&gt;decoded&lt;/th&gt;
&lt;th&gt;means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;AAAA&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[0, 0, 0, 0]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;column 0 is &lt;code&gt;a.js&lt;/code&gt; line 0, column 0: &lt;code&gt;function&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SAASA&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[9, 0, 0, 9, 0]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;column 9 is &lt;code&gt;a.js&lt;/code&gt; 0:9, named &lt;code&gt;add&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IAAIC&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[4, 0, 0, 4, 1]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;column 13 is &lt;code&gt;a.js&lt;/code&gt; 0:13, named &lt;code&gt;first&lt;/code&gt;. That’s the &lt;code&gt;n&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;EAAOC&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[2, 0, 0, 7, 1]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;column 15 is &lt;code&gt;a.js&lt;/code&gt; 0:20, named &lt;code&gt;second&lt;/code&gt;. That’s the &lt;code&gt;d&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GAClB&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[3, 0, 1, -18]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;column 18 is &lt;code&gt;a.js&lt;/code&gt; 1:2: &lt;code&gt;return&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Look at the third row. The &lt;code&gt;n&lt;/code&gt; is at column 13, but the segment says 4, and its name index says 1 when &lt;code&gt;first&lt;/code&gt; is at index 1 and &lt;code&gt;second&lt;/code&gt; at 2. &lt;strong&gt;Every field is a delta from the previous segment.&lt;/strong&gt; Column 13 is 9 + 4. Name 1 is 0 + 1. The &lt;code&gt;-18&lt;/code&gt; in the last row takes the original column from 20 back to 2, because &lt;code&gt;return&lt;/code&gt; is on the next source line, near its start.&lt;/p&gt;
&lt;p&gt;The rule that matters later: the generated column resets to zero at each new line (each &lt;code&gt;;&lt;/code&gt;), but &lt;strong&gt;the other four fields never reset&lt;/strong&gt;. They carry on from the last segment that had them, across the whole map.&lt;/p&gt;
&lt;p&gt;Deltas keep the numbers small, and small numbers encode in fewer characters.&lt;/p&gt;
&lt;h2 id=&quot;base64-vlq-in-one-paragraph&quot;&gt;Base64 VLQ in one paragraph&lt;/h2&gt;
&lt;p&gt;Each number is written as a variable-length quantity in Base64. A Base64 character carries 6 bits. The top bit says “another character follows”, and the other 5 are data, least significant group first. In the first character, the lowest data bit is the sign. So 0 is &lt;code&gt;A&lt;/code&gt;, 1 is &lt;code&gt;C&lt;/code&gt;, -1 is &lt;code&gt;D&lt;/code&gt;, and 16 needs two characters: 16 shifted left for the sign bit is 32, the low five bits (&lt;code&gt;00000&lt;/code&gt;) go first with the continuation bit set (&lt;code&gt;g&lt;/code&gt;), and the remaining 1 follows (&lt;code&gt;B&lt;/code&gt;). That gives &lt;code&gt;gB&lt;/code&gt;. Most deltas in a map fit in one character, which is why a mappings string looks like &lt;code&gt;AAAA,SAASA,IAAIC&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;gluing-two-maps-together&quot;&gt;gluing two maps together&lt;/h2&gt;
&lt;p&gt;Now a second file:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;b.js&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; greeting &lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &apos;hi&apos;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;console&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;greeting&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;b.min.js.map&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;sources&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;b.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;names&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;greeting&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;mappings&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;AAAA,MAAMA,OACN,YAAYA&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;The bundle is the two minified files joined with &lt;code&gt;;&lt;/code&gt; and a newline (the semicolon is there for &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion&quot;&gt;automatic semicolon insertion&lt;/a&gt;):&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;app.js&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt; add&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;	return&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; o &lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &apos;hi&apos;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;console&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;The obvious combined map concatenates the arrays and joins the two mappings strings with a &lt;code&gt;;&lt;/code&gt;, since &lt;code&gt;b&lt;/code&gt;’s code starts on the next line:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;sources&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;a.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;b.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;names&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;add&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;first&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;second&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;greeting&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;mappings&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;AAAA,SAASA,IAAIC,EAAOC,GAClB,OAAOD,EAAQC;AAAA,MAAMA,OACN,YAAYA&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;It’s valid JSON, it parses, and it’s wrong. Asking a decoder where line 2 of the bundle comes from:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;bundle position&lt;/th&gt;
&lt;th&gt;should be&lt;/th&gt;
&lt;th&gt;the glued map says&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;line 2, col 0&lt;/td&gt;
&lt;td&gt;&lt;code&gt;b.js&lt;/code&gt; 1:0&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a.js&lt;/code&gt; 2:17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;line 2, col 6&lt;/td&gt;
&lt;td&gt;&lt;code&gt;b.js&lt;/code&gt; 1:6 &lt;code&gt;greeting&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a.js&lt;/code&gt; 2:23, named &lt;code&gt;second&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;line 2, col 25&lt;/td&gt;
&lt;td&gt;&lt;code&gt;b.js&lt;/code&gt; 2:12 &lt;code&gt;greeting&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a.js&lt;/code&gt; 3:29, named &lt;code&gt;second&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;(Lines here are one-based, as an editor shows them.) Every position in the second file points into the first, at lines and columns &lt;code&gt;a.js&lt;/code&gt; doesn’t even have.&lt;/p&gt;
&lt;p&gt;The deltas explain it. &lt;code&gt;b&lt;/code&gt;’s first segment, &lt;code&gt;AAAA&lt;/code&gt;, means “same source, same line, same column as before”. In its own map, “before” was the starting state: source 0, line 0, column 0. In the glued map, “before” is &lt;code&gt;a&lt;/code&gt;’s last segment: source 0 (&lt;code&gt;a.js&lt;/code&gt;), line 1, column 17. So &lt;code&gt;b&lt;/code&gt;’s code lands in &lt;code&gt;a.js&lt;/code&gt;, starting just past where &lt;code&gt;a&lt;/code&gt; left off. Name indices drift the same way: &lt;code&gt;b&lt;/code&gt;’s name delta of 0 lands on &lt;code&gt;second&lt;/code&gt; instead of &lt;code&gt;greeting&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can’t fix that by editing the strings. Every segment after the join point would have to change.&lt;/p&gt;
&lt;h2 id=&quot;doing-it-properly-decode-shift-re-encode&quot;&gt;doing it properly: decode, shift, re-encode&lt;/h2&gt;
&lt;p&gt;The reliable way is to work on decoded numbers, not strings:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Decode each map’s &lt;code&gt;mappings&lt;/code&gt; to absolute values.&lt;/li&gt;
&lt;li&gt;Shift the second map’s source indices by the length of the first map’s &lt;code&gt;sources&lt;/code&gt;, and its name indices by the length of its &lt;code&gt;names&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Shift its generated lines by however many lines come before it in the bundle.&lt;/li&gt;
&lt;li&gt;Encode the whole thing again as one continuous sequence of deltas.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For the example, only &lt;code&gt;b&lt;/code&gt;’s first segment changes:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;glued:   …,EAAQC;AAAA,MAAMA,OACN,YAAYA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;correct: …,EAAQC;ACDjB,MAAMC,OACN,YAAYA&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;ACDjB&lt;/code&gt; reads: column 0, next source (+1), back one line (−1), back 17 columns (&lt;code&gt;jB&lt;/code&gt; is −17). That’s the step from &lt;code&gt;a&lt;/code&gt;’s last segment to &lt;code&gt;b.js&lt;/code&gt; line 0, column 0. The rest of &lt;code&gt;b&lt;/code&gt;’s segments were already relative to that one, so they stay the same, except &lt;code&gt;MAAMC&lt;/code&gt;, whose name delta becomes +1 to step from &lt;code&gt;second&lt;/code&gt; to &lt;code&gt;greeting&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Step 3 is where real bundles go wrong, because the line count has to include every line in the output, not just the minified code:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Separators.&lt;/strong&gt; Each newline you put between files adds a generated line, so it needs a &lt;code&gt;;&lt;/code&gt; in the mappings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Files that aren’t minified again.&lt;/strong&gt; A &lt;code&gt;.min.js&lt;/code&gt; from a vendor, passed through as it is, has no mappings, but its lines are still in the bundle. Write an empty group (&lt;code&gt;;&lt;/code&gt;) for each one, or every file after it is off by its line count.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Per-file &lt;code&gt;sourceMappingURL&lt;/code&gt; comments.&lt;/strong&gt; A minifier run on one file usually ends it with &lt;code&gt;//# sourceMappingURL=a.min.js.map&lt;/code&gt;. In a bundle, that line points at a map nobody serves and adds a line the combined map has to account for. Turn the comment off per file and write one at the end of the bundle.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;or-dont-merge-at-all-index-maps&quot;&gt;or don’t merge at all: index maps&lt;/h2&gt;
&lt;p&gt;The format has a second shape for exactly this case. An index map has no &lt;code&gt;mappings&lt;/code&gt; of its own. Instead it lists &lt;code&gt;sections&lt;/code&gt;, each placing a complete map at an offset in the generated file:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;file&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;app.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	&quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;sections&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;		{&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;offset&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;line&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; },&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;sources&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;a.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;],&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;…&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;…&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;		{&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;offset&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;line&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; },&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;sources&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;b.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;],&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt;…&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;…&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;	]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;Each section’s deltas start fresh, so the per-file maps go in unchanged and the bundler only tracks line offsets. It’s part of the format, now standardized as &lt;a href=&quot;https://tc39.es/ecma426/&quot;&gt;ECMA-426&lt;/a&gt;. Before you ship one, check that every tool that reads your maps accepts index maps: browser devtools, your error tracker, anything that symbolicates stack traces. If you can’t check them all, flatten into one map as above. Every consumer reads that.&lt;/p&gt;
&lt;h2 id=&quot;finding-the-map-and-the-files-behind-it&quot;&gt;finding the map, and the files behind it&lt;/h2&gt;
&lt;p&gt;Two URLs in a map are resolved relative to different things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;//# sourceMappingURL=&lt;/code&gt; comment (or a &lt;code&gt;SourceMap&lt;/code&gt; response header) is resolved against the &lt;strong&gt;script’s&lt;/strong&gt; URL.&lt;/li&gt;
&lt;li&gt;Each entry in &lt;code&gt;sources&lt;/code&gt; is resolved against the &lt;strong&gt;map’s&lt;/strong&gt; URL, after &lt;code&gt;sourceRoot&lt;/code&gt; is prepended if there is one.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If either is written as a root-absolute path (&lt;code&gt;/js/a.js&lt;/code&gt;), it breaks as soon as the app is served under a prefix, such as &lt;code&gt;https://example.com/myapp/&lt;/code&gt;. Devtools then asks for &lt;code&gt;https://example.com/js/a.js&lt;/code&gt;, gets a 404 and shows the minified code. Relative paths work under any prefix. If the original files aren’t served at all, &lt;code&gt;sourcesContent&lt;/code&gt; embeds their text in the map instead.&lt;/p&gt;
&lt;h2 id=&quot;testing-it&quot;&gt;testing it&lt;/h2&gt;
&lt;p&gt;A map that’s wrong in the middle passes every check that only looks at its shape. The useful test is the one in this post: pick tokens in the bundle, ask a decoder where they came from, and compare with the source. In JavaScript, &lt;a href=&quot;https://github.com/jridgewell/sourcemaps/tree/main/packages/trace-mapping&quot;&gt;&lt;code&gt;@jridgewell/trace-mapping&lt;/code&gt;&lt;/a&gt; does this with &lt;code&gt;originalPositionFor&lt;/code&gt;. Check one token from the first file, one from the last, and one from just after a file that was passed through unminified. Those three cover the mistakes above.&lt;/p&gt;
</content:encoded><category>javascript</category><category>source-maps</category><category>bundling</category></item><item><title>Move your MVC 5 bundles to ASP.NET Core without changing a single URL</title><link>https://cadamsmith.dev/writing/keep-your-bundle-urls/</link><guid isPermaLink="true">https://cadamsmith.dev/writing/keep-your-bundle-urls/</guid><description>DragonBundles serves the same bundle URLs on System.Web and ASP.NET Core, and replaces WebGrease with NUglify.</description><pubDate>Tue, 01 Dec 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you maintain an ASP.NET MVC 5 app, its CSS and JavaScript probably go through &lt;code&gt;System.Web.Optimization&lt;/code&gt;:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;bundles&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;Add&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(new&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt; ScriptBundle&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;~/bundles/jquery&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;    .&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;Include&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;~/Scripts/jquery-{version}.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;bundles&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;Add&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(new&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt; StyleBundle&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;~/Content/css&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;    .&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;Include&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;~/Content/bootstrap.css&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;~/Content/site.css&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;razor&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;Styles.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;Render&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;~/Content/css&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;Scripts.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;Render&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;~/bundles/jquery&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;That package has two problems today.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It doesn’t exist on ASP.NET Core.&lt;/strong&gt; Moving the app means replacing every bundle, usually with a build step or a different runtime bundler, and the bundle URLs (&lt;code&gt;/bundles/jquery&lt;/code&gt;, &lt;code&gt;/Content/css&lt;/code&gt;) change on the way. Anything that requested them, from cached pages to other sites to monitoring, breaks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It still minifies with WebGrease.&lt;/strong&gt; WebGrease is long abandoned and fails on modern syntax. In &lt;a href=&quot;https://github.com/cadamsmith/dragon-bundles/blob/main/bench/MinifyComparison/README.md&quot;&gt;a side-by-side run&lt;/a&gt; it rejected a stylesheet using custom properties, &lt;code&gt;clamp()&lt;/code&gt; and &lt;code&gt;:is()&lt;/code&gt;, and threw on a script using arrow functions, &lt;code&gt;?.&lt;/code&gt; and &lt;code&gt;??&lt;/code&gt;. NUglify minified both.&lt;/p&gt;
&lt;h2 id=&quot;same-registration-same-url-both-frameworks&quot;&gt;same registration, same URL, both frameworks&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cadamsmith/dragon-bundles&quot;&gt;DragonBundles&lt;/a&gt; is a bundler for both. A bundle named by a path is served at exactly that path, on .NET Framework and on ASP.NET Core:&lt;/p&gt;
&lt;p&gt;Classic ASP.NET:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;App_Start/BundleConfig.cs&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;bundles&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;AddScriptBundle&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;    &quot;~/bundles/jquery&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;~/Scripts/jquery-3.7.1.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;Views/Shared/_Layout.cshtml&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;razor&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D4A8FF&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;Html.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;ScriptBundle&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;~/bundles/jquery&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;ASP.NET Core:&lt;/p&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;Program.cs&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;app&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;UseBundling&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt;b &lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#E8EAED&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#8CC4FF&quot;&gt;AddScriptBundle&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;    &quot;~/bundles/jquery&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt; &quot;~/Scripts/jquery-3.7.1.js&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;figcaption class=&quot;code-title&quot;&gt;Views/Shared/_Layout.cshtml&lt;/figcaption&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;razor&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#FF9A80&quot;&gt;script-bundle&lt;/span&gt;&lt;span style=&quot;color:#E5C07B&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#B4D69A&quot;&gt;&quot;~/bundles/jquery&quot;&lt;/span&gt;&lt;span style=&quot;color:#A7ADB6&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;Both serve &lt;code&gt;/bundles/jquery?v=…&lt;/code&gt;, minified with NUglify, with a Subresource Integrity hash on the tag and a source map at &lt;code&gt;/bundles/jquery.map&lt;/code&gt;. So you can switch the legacy app to DragonBundles first, deploy, and check that nothing changed. Then you move to ASP.NET Core with the same file lists and the same URLs. If you also want identical markup, two options drop the extra attributes so the tags are exactly what &lt;code&gt;Styles.Render&lt;/code&gt; and &lt;code&gt;Scripts.Render&lt;/code&gt; emitted.&lt;/p&gt;
&lt;h2 id=&quot;three-systemweb-behaviours-that-bite-during-a-migration&quot;&gt;three System.Web behaviours that bite during a migration&lt;/h2&gt;
&lt;p&gt;Building this meant testing against the real System.Web pipeline: the actual &lt;code&gt;System.Web.Optimization&lt;/code&gt; handler, with views compiled at runtime. Three behaviours came out of that, each now pinned by a test, and each one changes what a browser receives:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;System.Web reorders your files.&lt;/strong&gt; With optimizations on, &lt;code&gt;BundleCollection.FileSetOrderList&lt;/code&gt; moves files such as &lt;code&gt;jquery*&lt;/code&gt;, &lt;code&gt;modernizr*&lt;/code&gt;, &lt;code&gt;reset.css&lt;/code&gt; and &lt;code&gt;normalize.css&lt;/code&gt; to the front, whatever order you listed them in. ASP.NET Core bundlers use the listed order, so a script that depends on order can break only after the move. DragonBundles has an opt-in &lt;code&gt;PreserveFileOrder&lt;/code&gt; so the legacy app serves the listed order first. (&lt;a href=&quot;https://github.com/cadamsmith/dragon-bundles/blob/main/tests/DragonBundles.Tests/SystemWeb/LiveHost/LiveSiteTests.cs&quot;&gt;test&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It serves &lt;code&gt;x.min.js&lt;/code&gt; when you listed &lt;code&gt;x.js&lt;/code&gt;.&lt;/strong&gt; In release mode, a listed file with a &lt;code&gt;.min&lt;/code&gt; sibling is served from the sibling (&lt;code&gt;FileExtensionReplacementList&lt;/code&gt;). Know which file you were actually shipping before you copy the list.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;CssRewriteUrlTransform&lt;/code&gt; ignores virtual directories.&lt;/strong&gt; Under an IIS application at &lt;code&gt;/myapp&lt;/code&gt;, it rewrites &lt;code&gt;url(../img/logo.svg)&lt;/code&gt; to &lt;code&gt;/Content/img/logo.svg&lt;/code&gt;, missing the &lt;code&gt;/myapp&lt;/code&gt; and so returning a 404. DragonBundles writes CSS urls relative to the bundle instead, on both frameworks, so they work under any virtual directory or &lt;code&gt;PathBase&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;when-to-use-something-else&quot;&gt;when to use something else&lt;/h2&gt;
&lt;p&gt;DragonBundles is for an app that runs on System.Web today and is moving, or may move, to ASP.NET Core. Other tools fit other cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A new ASP.NET Core app:&lt;/strong&gt; &lt;a href=&quot;https://github.com/ligershark/WebOptimizer&quot;&gt;WebOptimizer&lt;/a&gt; and &lt;a href=&quot;https://github.com/Shazwazza/Smidge&quot;&gt;Smidge&lt;/a&gt; are established runtime bundlers for ASP.NET Core, and Smidge released 5.1.0 in November 2026. &lt;a href=&quot;https://github.com/adams85/bundling&quot;&gt;Bundling&lt;/a&gt; (&lt;code&gt;Karambolo.AspNetCore.Bundling&lt;/code&gt;) was built as a .NET Core replacement for System.Web.Optimization, with a similar API, and released 3.10.3 in November 2026. All three run on ASP.NET Core only, so none of them can serve the legacy app while it is still on System.Web.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bundling at build time:&lt;/strong&gt; &lt;a href=&quot;https://github.com/madskristensen/BundlerMinifier&quot;&gt;BundlerMinifier&lt;/a&gt; writes bundled files during the build and also works in .NET Framework projects. Its last NuGet release was 3.2.449, in June 2020.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A frontend with a node toolchain:&lt;/strong&gt; Vite or esbuild do far more than any of these (modules, TypeScript, tree shaking). They write static files at build time (Vite adds a content hash to file names by default), so keeping the old extensionless bundle URLs such as &lt;code&gt;/bundles/jquery&lt;/code&gt; takes extra routing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If your app has no System.Web history, any of those is a fine choice.&lt;/p&gt;
&lt;h2 id=&quot;how-its-checked&quot;&gt;how it’s checked&lt;/h2&gt;
&lt;p&gt;Every commit runs the MVC 5 sample in IIS (integrated pipeline, at a site root and under a virtual directory) and the ASP.NET Core sample on Kestrel (at a root and under a &lt;code&gt;PathBase&lt;/code&gt;). Headless Chromium then checks each one:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SRI is accepted;&lt;/li&gt;
&lt;li&gt;the CSS applies and the scripts run;&lt;/li&gt;
&lt;li&gt;source maps resolve the way devtools resolves them;&lt;/li&gt;
&lt;li&gt;both apps serve every bundle at the same path.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/cadamsmith/dragon-bundles/blob/main/docs/migration-walkthrough.md&quot;&gt;migration walkthrough&lt;/a&gt; is built on those two samples.&lt;/p&gt;
&lt;h2 id=&quot;try-it&quot;&gt;try it&lt;/h2&gt;
&lt;figure class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code cadamsmith&quot; style=&quot;background-color:#181b1e;color:#e8eaed; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;dotnet add package DragonBundles&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cadamsmith/dragon-bundles#readme&quot;&gt;README&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cadamsmith/dragon-bundles/blob/main/docs/migration-walkthrough.md&quot;&gt;Migration walkthrough&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/cadamsmith/dragon-bundles/releases/tag/v0.5.0&quot;&gt;0.5.0 release notes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Issues and questions are welcome on &lt;a href=&quot;https://github.com/cadamsmith/dragon-bundles/issues&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>dotnet</category><category>aspnet</category><category>migration</category><category>dragonbundles</category></item></channel></rss>