The Parallel module sets $scripts src to "//js-subdomain.examples/sites/default/files/js/js_b918e9e12007a05d73f9101cf854afde.js"
On line 94 of javascript_aggregator.module, the regex pattern filters out any path other than base_path() . file_directory_path():
$path_to_files_directory = base_path() . file_directory_path();
$pattern = "!(<script type=\"text\/javascript\" src=\"$path_to_files_directory)(.*?)(\"(.*?)><\/script>)!";
if (preg_match_all($pattern, $scripts, $matches) > 0) {
As a result, any script whose path has been rewritten by Parallel is skipped by JS aggregator.
Vianney Stroebel
Likwid - Spécialistes Drupal - Paris
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | parallel-619112-41.patch | 2.22 KB | mikeytown2 |
| #40 | parralel_619112b.diff | 2.32 KB | dalin |
| #4 | parralel_619112.diff | 1.92 KB | dalin |
Comments
Comment #1
mikeytown2 commentedSounds like I need to change the weight on my module so it runs near the end.
Comment #2
dalinHmmm, I didn't look into the details. I just changed the weight to 10 and saw no change. JS aggregated files are not being rewritten.
Comment #3
dalinAh, on further research it looks like it needs to fire after jquery update which has a weight of 99. When I set the weight of Parallel to 100 it works as expected.
Comment #4
dalinTurns out that jQuery Update is also manipulating the theme registry in tricky ways. And we have to do the same so that our code runs last. The code in this patch is taken almost verbatim from jQuery Update.
Comment #5
mikeytown2 commentedchanged update 6001 to 6100
added in a hook install function
committed
Comment #6
philbar commentedI'm still having an issue with 6.x-1.0-beta2.
Parallel enabled - JS is aggregated but not compressed.
Parallel disabled - JS is compressed and I get a file with .jsmin.js attached to the file name.
Comment #7
ak commentedI can confirm that, same problem by me.
Comment #8
srobert72 commentedSubscribing
I moved
<?php echo $scripts ?>to bottom of my template (page.tpl.php) just before closure.JavaScript from header aren't minified. But those in footer are.
Both URL point to my CDN server.
Comment #9
srobert72 commentedI tried some debug traces with some "echo".
And here is interesting result :
Javascript_Aggregator search pattern could not operate correctly in second case because URL has already been replaced by Parallel module.
Are we sure Parallel module always operates after Javascript_Aggregator ?
Comment #10
srobert72 commentedMaybe this code from Javascript_Aggregator causes this issue :
Modules weights have no effect because Javascript_Aggregator forces to be always called last one.
Issue to be assigned to Javascript_Aggregator module ?
Hmmm no DEV release since July 2009, I'm afraid it will not be fixed rapidly.
Is it possible to fixed it in another way in Parallel module ?
Comment #11
srobert72 commentedI found a solution with modified Javascript_Aggregator code :
In javascript_aggregator.module file (function _javascript_aggregator_minify($scripts))
replace :
by
Comment #12
SaxxIng commentedI can confirm that the "patch" proposed by srobert72 works very well on my test site!
Comment #13
srobert72 commented@SaxxIng
Thank you for testing my patch.
Problem remains this patch is for Javascript_Aggregator and not Parallel module.
We could reassign this issue to Javascript_Aggregator module.
But no DEV release since nearly one year for Javascript_Aggregator module. And I don't know if maintainer would want to fixe something concerning another module.
That's why I leave this issue to Parallel module.
EDIT on April 13, 2010
Javascript_Aggregator module has just released new DEV version.
I was wrong thinking there's no more activity in this module.
I proposed to patch it in order to fix issue with Parallel module.
See #770374: Incompatible with Parallel module
Comment #14
dalinI believe that you just need to replicate the approach that I took in the patch that I submitted. The problem in that case was jQuery Update. Parallel's theme functions needs to run after jQuery Update. This was accomplished with a combination of setting the module weight to one heavier than jQuery Update, and use hook_theme_registry_alter() to move Parallel's theme function to be last. To make this approach work with JavaScript Aggregator all you should need to do is to make the weight of Parallel to be one heavier than JavaScript Aggregator (Parallel's implementation of hook_theme_registry_alter() just needs to run after JavaScript Aggregator's). The weight of JavaScript Aggregator is 9999 so setting the weight of Parallel to 10000 should do the trick.
Comment #15
srobert72 commentedThis feature has been added to Javascript_Aggregator module.
It now proposes option to serve JS files from external site.
#533190: PATCH: allow serving js files from an external file server
Solution without any patch is to configure base URL in Parallel module to serve images and CSS, and base URL in Javascript_Aggregator to serve JS files.
EDIT on April 13, 2010
Sorry for wrong news, this Javascript_Aggregator patch is for 5.x branch and not 6.x
Comment #16
dalinWell that's a bit crufty, but oh well.
Comment #17
srobert72 commented@mikeytown2
What solution do you prefer ?
Comment #18
mikeytown2 commentedhmmm... I have some code that makes parallel compatible with boost; looks like I need to modify boost for the new JavaScript Aggregator patch.
Comment #19
srobert72 commentedEDIT #15
Sorry for wrong news, this Javascript_Aggregator patch is for 5.x branch and not 6.x
Comment #20
srobert72 commentedEDIT #13
Javascript_Aggregator module has just released new DEV version.
I was wrong thinking there's no more activity in this module.
I proposed to patch it in order to fix issue with Parallel module.
See #770374: Incompatible with Parallel module
Comment #21
derjochenmeyer commentedI committed the code suggested in #11 to Javascript Aggregator. Please try new dev version and report here: #770374: Incompatible with Parallel module
Thanks.
Comment #22
srobert72 commentedPatch commited in Javascript_Aggregator module works properly.
Seems this issue could be closed.
Comment #23
mikeytown2 commentedreopen if something new happens
Comment #24
dalinThe patch mentioned in #20 and #21 was either never committed to JavaScript Aggregator, or it was rolled back. This is a good thing because JS Aggregator is the wrong place to make such a change (Any module should only be doing one thing).
To get Parallel working with JS Aggregator simply requires the weight of Parallel to be heavier. It must be 10000.
I would write a patch to do this, but I think it would be easier for @mikeytown2 to just edit the .install file and change the weight from 100 to 10000.
Comment #25
mikeytown2 commentedHere's the query
Committed
http://drupal.org/project/cvs/548828
Comment #26
srobert72 commented@dalin #24
Patch is still in CVS (line 102):
http://drupalcode.org/viewvc/drupal/contributions/modules/javascript_agg...
I don't understand why it was wrong place because Javascript_Aggregator continues to do just its work without any interaction with Parallel. Any trace of Parallel in Javascript_Aggregator code.
Comment #27
dalinBefore Mikeytown2's patch in #25, the current stable version of Parallels + the current stable version of JavaScript Aggregator resulted in the JS file being moved to the CDN, but it was not minified.
One of the rules of good programming is that each component should do just one atomic thing and should not be affected by enabling/disabling other components. If you either build a component to do X, Y, Z and wash your dishes you quickly get into a maintenance nightmare. If you have to create workarounds for other components you also get into a maintenance nightmare. The logical way to have the system work is for Parallels to fire last to rewrite finalized URLs from the local system to the remote system. JSA should not need to write preg_replace workarounds for cases when Parallels is or isn't installed.
Comment #28
srobert72 commentedAnd don't you think it could be a limitation in JSA to always search for relative URL ?
Doing this it will never be compatible with other modules which rewrite URL such CDN like modules.
Changing weight is a sort of workaround you speak about. You set your weight depending on other's weight.
I agree your solution works and it's a good one. Don't misunderstand me.
But I'm not sure mine was so bad. I really think JSA couldn't operate in all cases depending on which modules operate before it.
Comment #29
srobert72 commentedFor information there is same issue in ColorBox module. I've just checked it has weight 0.
#773006: Add support for the Parallel module
Comment #30
derjochenmeyer commented@dalin #24
The patch mentioned above did get committed to 6.x-1.x-dev of Javascript Aggregator! Since it's a minor change I dont think it needs to be rolled back?
You are also right, about #788202: The current module weight is absurdedly high.
Comment #31
mikeytown2 commentedso, change this to 110?
Comment #32
dalin@mikeytown2 I would say no, the current regex workaround that JSA is trying to use to make itself run after Parallel isn't working.
Comment #33
srobert72 commented@dalin
But it works for me and for SaxxIng #12...
You said it hasn't been commited, but it was.
Are you sure you have this piece of code in your Drupal code ?
Check .../modules/javascript_aggregator/javascript_aggregator.module line 102
Comment #34
dalinJSA 6.1.x dev has some regex that should work, but the current release does not.
Comment #35
srobert72 commentedYes and weight patch for Parallel has been commited to DEV branch too.
We are not comparing official releases.
But we are searching right solution in DEV branches before making it official.
Comment #36
derjochenmeyer commentedIn fact, this all in 6.x-1.x-dev (only!) at the moment.
Comment #38
Anonymous (not verified) commentedI'm using latest 1xdev for Parallel and latest dev for JSA. But the js url is not being rewritten.
Parallel has a weight of 10000, and JSA dev is now 109.
Also same issue with the CSS Gzip module, urls not being rewritten.
Comment #39
Anonymous (not verified) commentedFirst thing I noticed is that my CSS Gzipped & JSA files have abolute paths, like
http://www.domain.com/sites/default/files/css/css_3243423.css.So Parallel's str_replace "src=/" doesn't work. I fixed it in parallel by using $base_url:
My image URLs are relative, just CSS & JS is absolute - and only when using CSS Optimize and JSA.
So... does anyone else have abolsute urls?
Comment #40
dalinHrrrrm. Just noticed that all of a sudden my aggregated CSS and JS have absolute URLs. Not sure what is causing this or why. I don't think it's core, but I don't have any modules on this site that I suspect either. Well here's a patch that handles both relative and absolute paths for CSS and JS.
Comment #41
mikeytown2 commentedpatch file didn't apply using CVS for some strange reason... my guess is the 2 random
\ No newline at end of filelines in there.can you verify that this patch does what your looking for?
Comment #42
mikeytown2 commentedeh looks good
committed.
Comment #44
momper commentedsub