简体   繁体   中英

Javascript stops working when aggregation is enabled in Drupal 7

Javascript stops working when aggregation is enabled in Drupal 7 while I am logged in and admin toolbar menu is visible. When I am not logged in and admin menu is not visible everything works fine. Also when aggregation is OFF and I am looged in and admin menu is visible everything works fine.

So when aggregation is ON and admin menu on, javascript of the site does not work.

Any ideas ?

Most likely one of your JS files has a syntax error like a trailing ',' at the end of an object definition or a missing ';'.

For example:

var a = {
  a:1,
  b:2,
  c:3, // trailing ','
} // missing ';'

The reason it may only appear with the admin tool bar could be one of the following:

1) The order in which the files are aggregated causes the syntax error to be placed ahead of the code for the admin toolbar causing JS to error out before the toolbar has a chance to display. (Syntax errors cause many runtime JS compilers to stop processing the whole file, which in the case of aggregated files, can mean a large chunk of your JS never gets to run)

2) The JS file the syntax error resides is ONLY added when the admin toolbar is present.

The first place I would check is any custom JS files that you have created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM