htmlcompressor icon indicating copy to clipboard operation
htmlcompressor copied to clipboard

Add the ability to include external CSS and JS

Open GoogleCodeExporter opened this issue 10 years ago • 9 comments

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

Original issue reported on code.google.com by [email protected] on 10 Jul 2011 at 11:56

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

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 [email protected] on 10 Jul 2011 at 4:11

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

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 [email protected] on 10 Jul 2011 at 5:37

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

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 [email protected] on 10 Jul 2011 at 5:50

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

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 [email protected] on 10 Jul 2011 at 5:58

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

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 [email protected] on 10 Jul 2011 at 6:23

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

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 [email protected] on 10 Jul 2011 at 6:34

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

I will probably wait for more feedback to see if anyone else needs this feature 
before implementing it.

Original comment by [email protected] on 10 Jul 2011 at 9:23

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

[deleted comment]

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter

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 [email protected] on 2 Oct 2012 at 12:25

GoogleCodeExporter avatar Nov 27 '15 21:11 GoogleCodeExporter