wpsharks / html-compressor

HTML Compressor. Combines and compresses CSS/JS/HTML code.
https://websharks.github.io/html-compressor/
GNU General Public License v3.0
38 stars 9 forks source link

cross orginin js problems with HTML Compression #43

Closed brbrbr closed 10 years ago

brbrbr commented 10 years ago

On a worpress network website the compressor is generating url to the original website and not the mapped domain. Resulting in cross origin problems for js and font

thus network is : example.com original site is : mysite.example.com

domain mapping mysite.example.com <-> www.mapped-example.com

now the url's for js/css/font etc should all point to www.mapped-example.com and not mysite.example.com

problem that might occur:

original js has (hardcoded) ajax request to www.mapped-example.com compressed javascript is located on mysite.example.com/cache/..../compressed.js cross origin...

same happens with fonts

jaswrks commented 10 years ago

@brbrbr Thanks for this report! Yes, I can see where this will cause some problems.

Other than telling the HTML Compressor to exclude these JS files that contain cross-domain references, do you have any other ideas on how we might go about improving compatibility in this regard?

cc @raamdev

brbrbr commented 10 years ago

quick-cache picks the wrong base url

should be www.mapped-example.com not mysite.example.com as in the example above. That would solve any cross domain references, assuming all other themes and plugin take care of picking the right base url.

Maybe the problem is that you are using WP_CONTENT_URL and not appling the content_url filters to get the correct domain name? See the function content_url in wp-includes/link-template.php

I can try to digg into it later

jaswrks commented 10 years ago

quick-cache picks the wrong base url

Thanks for the follow-up. Hmm. I assume that you are using this plugin for domain mapping, correct? https://wordpress.org/plugins/wordpress-mu-domain-mapping/

Maybe the problem is that you are using WP_CONTENT_URL and not appling the content_url filters to get the correct domain name? See the function content_url in wp-includes/link-template.php

I just ran a check to confirm this. QCP uses content_url() so I don't think that's the issue. I will take a closer look at this also, but it would be great if you can post anything else that you find. Thanks!!

brbrbr commented 10 years ago

right,

however content_url is returning the url the the original url not the mapped url.

that's odd would expect that content_url uses the mapped domain not the network domain as it does for functions like plugin_url etc.

Anyhow I still think that your compressed css and js files should be fetched from the mapped domain.

will digg into to, maybe i can solve the problem by writing a filter for content_url

good luck

brbrbr commented 10 years ago

Ok,

looks like it's more a problem with the domain mapper plugin than yours.

https://wordpress.org/support/topic/proposal-two-more-filters?replies=4

sorry for that

btw : I think you should remove your footer as well when compressing the html......