views:

181

answers:

2

I am looking for a simple commandline script/program to automatically "inline" all external css and javascript references for a html file. I basically want to create a single self-contained html file suitable for sending via E-Mail. An additional bonus would be if it could also inline images as data: UIRs, but that part is not so important.

+1  A: 

If it's not something that needs to be automated and you're using Windows you could open the web page in Internet Explorer and save it as 'Web Archive, single file (*.mht)'. This will pack everything into a single file, including CSS, JavaScript and images. Note that the recipients needs to have access to Internet Explorer to be able to open the Web Archive. Neither Google Chrome nor Firefox supports mht files, so it's probably a Microsoft only feature.

Jan Aagaard
Opera supports it too, and it's a MIME multipart format so e-mail clients should support it: http://stackoverflow.com/questions/793404/do-most-email-clients-support-mhtml
mercator
+1  A: 

EDIT : I wrote a little Python script for fun. It seems to work pretty well :

Inline2Mail

Or you can still try with :

Front compiler does something like that but it implies javascript. You have an online solution as well, with premailer. Finally you have a Python and a Ruby script to do it.

e-satis
I'm trying to "import" external references like <script src=""> and @import url("foo.css") into my html file to make it a single file. Both the python and ruby script appear to do something else.
Sec
Premailer does this import, whereas the python script inject the css directly in the tags. They are complementary.
e-satis