Source Maps Utilities Php Library

Public Announcement of a new php library for working with source maps: koala-framework/sourcemaps

Source maps help with debugging minified javascript or css files, see the html5rocks article for a short introduction.

This library originated from koala framework where we support source maps created by sass and uglifyjs.


  • creating mappings
  • reading mappings
  • source map aware string replace for existing mapping
  • concat maps (optimized for best performance)

Use cases

Concat into a single file

A common pattern is the creating of a single javascript and css file out of many source files for better performance (as the browser has to make less requests).This library allows concating multiple source maps and keeps the mappings intact.

During development performance is key, so we implemented this concat as performant as possible: we don't parse and write the whole mapping information, instead we only work with the strings and put them together - with an offset correction injected - so the maps stay intact.

String replacements

When different versions of a file need to be generated (eg. translation or replacing a base path) it makes sense to cache the uglifyjs compiled file and do required string replacements on that.

Example usage

$map = new Kwf_SourceMaps_SourceMap($mapContents, $minimiedFileContents);
//create new map
$map = Kwf_SourceMaps_SourceMap::createEmptyMap($minimiedFileContents);
$map->addMapping(2, 3, 10, 12, 'foo.js'); //$generatedLine, $generatedColumn, $originalLine, $originalColumn, $originalSource, $originalName = null)
//merge two maps
//perform string replacement
$map->stringReplace('foo', 'bar');

Found any issue, bug or have a question? Create an issue on github.

This entry was posted in Koala Framework, Web Development by Niko Sams. Bookmark the permalink.

One Thought on "Source Maps Utilities Php Library"

[]Автопрокат ПАРК[/url] предлагает бюджетные цены на [цены/]прокат автомобилей в Алуште[/url]. Качественные условия аренда на авто для путешествий в Алуште. В нашем прокате Вы можете арендовать автомобиль в Феодосии на выходные с кондиционером.

Leave a Reply

Your email address will not be published.