I want to turn off AdvAgg for the H5P node type. Apparently there is a conflict or bad javascript in the H5P such that jsmin does not work. I have also tried disabling js minimization for all H5P files, but that did not help. So next step disable AdvAgg entirely for H5P nodes.

But how can I do that?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webservant316 created an issue. See original summary.

webservant316’s picture

Perhaps I could manually set $_GET['AdvAgg']=1 if $node->type=='h5p_content'. But what hook would I use to make this assignment?

mikeytown2’s picture

hook_init() or hook_page_alter() will work.

function hook_page_alter() {
  // Get the current active node object if present.
  $node = menu_get_object();
  if (!empty($node) && !empty($node->type) && $node->type === 'h5p_content') {
    // Disable js compression on this page
    $GLOBALS['conf']['advagg_js_compressor'] = 0;
  }
}
webservant316’s picture

Works! awesome, Thanks! That could a feature request for AdvAgg. Add the ability to enable or disable by content type and or path, similar to Block visibility. AdvAgg is awsome, however, it does not play well with certain modules and so this could increase the use base if it was easier to disable AdvAgg for problematic situations.

Changing to feature request.

webservant316’s picture

Title: How can I turn off AdvAgg for a particular node type, the H5P type?? » Turn off AdvAgg for a particular node type, such as the H5P type!!
Category: Support request » Feature request
webservant316’s picture

I needed to extend this to also turn of AdvAgg for H5P quiz questions...

function custom_module_page_alter() {
/*** Get the current active node ***/
$node = menu_get_object();
if (!empty($node->type) && ($node->type == 'h5p_content' || ($node->type == 'quiz' && arg(2)=='take'))) {
	$GLOBALS['conf']['advagg_js_compressor'] = 0;
}
}
mikeytown2’s picture

Title: Turn off AdvAgg for a particular node type, such as the H5P type!! » Turn off AdvAgg JS Compression for a particular node type, such as the H5P type.
Component: Miscellaneous » Compression/Minification

Any way to ID the js that is causing issues for you? What js compressor are you using? Under Licensing comments on the js compression page select the "Do both; try to keep important comments and provide a link" radio and then open up the browser console. Any JS errors should be listed there. Once you know the file that is causing issues you should be able to pinpoint the js that is not getting minified correctly.

webservant316’s picture

using jsmin, the compiled C version, though the php jsmin also fails the same way.

I am using FF, but don't understand how to copy the errors out of the browser console. Any tips. I do see related errors, but not sure how to get the what is helpful over here. Below are the error messages and the lines of code.

H5P Chart - Instance undefined error on this line

else if(instance.$!==undefined&&instance.$.trigger!==undefined){instance.$.trigger(eventType);}};H5P.on=function(instance,eventType,handler){if(instance.on!==undefined){instance.on(eventType,handler);}

H5P Chart - Unable to find constructor for: H5P.Chart 1.0

return instance;};H5P.error=function(err){if(window.console!==undefined&&console.error!==undefined){console.error(err.stack?err.stack:err);}};H5P.t=function(key,vars,ns){if(ns===undefined){ns='H5P';}

H5P Multiple choice - Missing ';' before statement

EJS.Helpers.prototype.date_tag=function(name,value,html_options){if(!(value instanceof Date)) value=new Date() var month_names=["January","February","March","April","May","June","July","August","September","October","November","December"]; var years=[],months=[],days=[]; var year=value.getFullYear(); var month=value.getMonth(); var day=value.getDate(); for(var y=year-15;y<year+15;y++) { years.push({value:y,text:y}) } for(var m=0;m<12;m++) { months.push({value:(m),text:month_names[m]}) } for(var d=0;d<31;d++) { days.push({value:(d+1),text:(d+1)}) } var year_select=this.select_tag(name+'[year]',year,years,{id:name+'[year]'}) var month_select=this.select_tag(name+'[month]',month,months,{id:name+'[month]'}) var day_select=this.select_tag(name+'[day]',day,days,{id:name+'[day]'}) return year_select+month_select+day_select;}

H5P Multiple choice - Unable to find constructor for: H5P.MultiChoice 1.6

return instance;};H5P.error=function(err){if(window.console!==undefined&&console.error!==undefined){console.error(err.stack?err.stack:err);}};H5P.t=function(key,vars,ns){if(ns===undefined){ns='H5P';}

H5P Multiple choice - Instance is undefined

else if(instance.$!==undefined&&instance.$.trigger!==undefined){instance.$.trigger(eventType);}};H5P.on=function(instance,eventType,handler){if(instance.on!==undefined){instance.on(eventType,handler);}

mikeytown2’s picture

Didn't know this was from a module
https://www.drupal.org/project/h5p
https://www.drupal.org/project/quiz_h5p

I'm assuming that you've tried the "Per File Settings" on the admin/config/development/performance/advagg/js-compress page and disabled compression for the js files right?

Once we have a good way to reproduce the bug, filing a bug report here should be helpful https://github.com/sqmk/pecl-jsmin

webservant316’s picture

Yes I tried turning off compression for all the h5p js files, but that did not work. I am not sure why. However, disabling AdvAgg entirely for H5P nodes does solve my problem.

mikeytown2’s picture

Title: Turn off AdvAgg JS Compression for a particular node type, such as the H5P type. » Fix h5p module js compression issues
Category: Feature request » Support request
mikeytown2’s picture

Looking for the strings of text found in #8 in https://github.com/h5p/h5p-chart and I'm coming up empty. https://h5p.org/node/6729 is the chart; I have https://www.drupal.org/project/quiz_h5p installed and trying to reproduce this issue, but having trouble. What versions of everything are you using?

webservant316’s picture

Drupal 7.50
Advanced CSS/JS Aggregation 7.x-2.18
H5P - Create and Share Rich Content and Applications 7.x-1.18
Quiz 7.x-4.0-rc2
+100 other modules

mikeytown2’s picture

FileSize
32.25 KB

Was using the 5.x branch of quiz. switched to the 4.x branch and I still can't reproduce this. Here's an example screenshot of the per file settings. Can you give me a screenshot of the files you have disabled? Knowing the filename would be very helpful.

webservant316’s picture

I have attached a list of the H5P files, but I don't think that will help. I was not able to fix the problem by excluding compression for a particular file, but only by turning compression completely off for H5P Chart and Multiple Choice.

I used this code which forces no aggregation for all H5P types and all Quiz questions. It is a brute force solution, but it works.

function custom_module_page_alter() {
/*** Get the current active node ***/
$node = menu_get_object();
if (!empty($node->type) && ($node->type == 'h5p_content' || ($node->type == 'quiz' && arg(2)=='take'))) {
	$GLOBALS['conf']['advagg_js_compressor'] = 0;
}
}

Also see attached screen shots.

  • mikeytown2 committed d72b58e on 7.x-2.x
    Issue #2803335 by mikeytown2: Do not inline wrap H5PIntegration...
mikeytown2’s picture

I did have one problem with defer/footer. This fixes the intermittent issue I was encountering. Still working on reproducing your exact issue.

mikeytown2’s picture

Status: Active » Closed (cannot reproduce)

I can't reproduce this issue; reopen if there is an actionable code change that can be made.