             content: utils.code.compress scripts
             origin: @links.scripts
         @remove ('/' + script) for script in @links.scripts
+        
         callback null, this
 
     # (7) rewrite HTML files to point to our optimized scripts and styles
     rewriteHtml: (self..., callback) ->
-        ###
-        # TODO: we can't just remove all scripts -- absolute references to
-        # external scripts and styles should be kept intact
-        $('script').remove()
-        script = window.document.createElement('script')
-        script.type = 'text/javascript'
-        script.src = 'application.min.js'
-        window.document.getElementsByTagName('head')[0].appendChild script
-        ###
-        callback null, this        
+        entrypoint = @find @relativeEntrypoint
+    
+        utils.html.parse entrypoint.content, (errors, window) =>
+            $ = window.$
+        
+            $('script').each ->
+                el = $ @
+                # we can't remove all scripts -- absolute references to
+                # external scripts and styles should be kept intact
+                if el.attr('src').indexOf('/') isnt 0
+                    el.remove()
+                if el.hasClass 'jsdom'
+                    el.remove()
+                
+            script = window.document.createElement('script')
+            script.type = 'text/javascript'
+            script.src = 'application.min.js'
+            window.document.getElementsByTagName('head')[0].appendChild script
+
+            entrypoint.content = window.document.outerHTML
+            
+            callback null, this        
 
     report: ->
-    
 
 exports.bundle = (entrypoint, callback) ->
     bundle = new Bundle entrypoint


    # (6) concatenate and optimize scripts and stylesheets
    optimize: (self..., callback) ->
    
        scripts = @links.scripts
            .map (ref) =>
                # TODO: everything should exist and have content, so 

                return @files.splice i, 1

    find: (path) ->
        _.find @files, (file) -> path in [file.path, file.originalPath]

    # (1) create an unoptimized bundle
    create: (callback) ->
