macray / htmlcompressor

Automatically exported from code.google.com/p/htmlcompressor
Apache License 2.0
0 stars 0 forks source link

Add the ability to include external CSS and JS #44

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The files would be named in the CLI, minified, compressed, and included as 
*inline* CSS/JS.

Original issue reported on code.google.com by abom...@gmail.com on 10 Jul 2011 at 11:56

GoogleCodeExporter commented 9 years ago
You mean if you have html:

<link href="/css/styles.css" rel="stylesheet" type="text/css"/>
<script src="/js/script.js"></script>

it would turn into:

<style>
    //styles.css content
</style>
<script>
    //script.js content
</script>

The problem is how to identify those files, lets say you have:

<script src="http://example1.com/script.js"></script>
<script src="http://example2.com/js/script.js"></script>
<script src="script.js"></script>
<script src="../../script.js"></script>

Which parameters to pass to the compressor that would indicate which script to 
replace with which file?

Original comment by serg472@gmail.com on 10 Jul 2011 at 4:11

GoogleCodeExporter commented 9 years ago
Sorry, I haven't been clear; The files would passed to the compressor via 
parameters like --external-js, --external-css.
Converting HTTP requests to inline JS/CSS is another concern.

Original comment by abom...@gmail.com on 10 Jul 2011 at 5:37

GoogleCodeExporter commented 9 years ago
But how to figure out which file to insert into which position? You can't just 
provide a list of filenames as the same filename could mean different script 
(as shown in the example above). It should be something like key value pairs:

"script.js" -> "c:/dir1/script.js"
"../../script.js" -> "c:/dir2/script.js"

Original comment by serg472@gmail.com on 10 Jul 2011 at 5:50

GoogleCodeExporter commented 9 years ago
Ah, no, actually the HTML file would *not* have links to the JS/CSS files like 
<script src=script.js></script>. One would just specify the wanted files and 
they would be injected in the <head> of the HTML.

Original comment by hellosex...@gmail.com on 10 Jul 2011 at 5:58

GoogleCodeExporter commented 9 years ago
Hm, I don't see a point then. What is the purpose of this feature? How are you 
going to develop the page without css or js in it? Why would you want to insert 
them only at the compression stage without even having control where on the 
page they will be inserted (which is important)? Inserting javascript into 
<head> should be your last option if you care about optimization.

I could understand replacing existing tags with inline content to save http 
requests, but what you are describing looks like some very exotic task I am not 
sure anyone else would ever use.

Original comment by serg472@gmail.com on 10 Jul 2011 at 6:23

GoogleCodeExporter commented 9 years ago
Yes, said like that... I guess that would just suit my specific need.

Although, following your method, one could pass each file to the script with 
--external scripts.js=c:/dir1/script.js and so on. What do you think?

Original comment by hellosex...@gmail.com on 10 Jul 2011 at 6:34

GoogleCodeExporter commented 9 years ago
I will probably wait for more feedback to see if anyone else needs this feature 
before implementing it.

Original comment by serg472@gmail.com on 10 Jul 2011 at 9:23

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi, I'd like to see this feature added to the taglib.  It could work the way 
"packtag" currently does... you specify a "src" attribute with either CSS or JS 
URLs.  These URLs can be both external and/or internal.  For example,

<pack:script>
<src>/assets/javascripts/library/prototype/prototype.js</src>
<src>http://code.jquery.com/jquery-latest.js</src>
</pack:script>

<pack:style>
<src>/assets/stylesheets/common/normalize.css</src>
<src>/assets/javascripts/library/jquery/jquery-ui/css/smoothness/jquery-ui.css</
src>
</pack:style>

Original comment by ram...@gmail.com on 2 Oct 2012 at 12:25