Perhaps I'm asking too much but asking it is much better than assuming it doesn't exists.
In order to create a converter of webpages into single file (including all the external resources the html), I'm planning to use Data URI Scheme. But the problem with such a conversion is that lots of pages incorporate Javascript codes to come up with the URI of a resource. i. e. it's completely ordinary for a page to set the src
of an image with JS.
In worst case scenario, the URI is composed in which cases it's absolutely impossible to replace the URI with Data URI Scheme, e. g. img.src = 'domain.com/' + some_variable + '.png';
.
The only way I can think of to overcome such scenarios and all other, is to introduce a middle block of code after URI is changed and before it is downloaded. If such opportunity exits, I can work on the requested URI and replace it with appropriate Data URI Scheme. It also benefits from a global Data URI Scheme storage that leads to smaller html file size.
Does anyone know if such opportunity exists? Or if one can create it?
[EDIT]
Here's how I would like my single-file webpage to be:
<script>
var uri_dictionary = {
'http://www.domain.com/1.png': 'data:image/png;base64,iVBORw0KGgoAAAAN...',
'http://www.domain.com/2.png': 'data:image/png;base64,iVBORw0KGgoAAAAN...'
};
function translateURI(url) {
if (uri_dictionary[url]) {
return uri_dictionary[url];
}
else {
return url;
}
}
</script>
The above is a simplified version of the code that I'm planning to inject into the single-file webpage that I'm going to generate. It's just that the translateURI
function needs to intercept all the outgoing requests before they are sent. And replace their requested URI in feasible cases.