googleanalytics_cron() calling drupal_clear_js_cache() & boost

mikeytown2 - May 31, 2009 - 09:16
Project:Google Analytics
Version:6.x-2.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Is there a really good reason for clearing the JS cache? I'm trying to figure out why some pages components are broken and possible ways around it #413908: Cache js/css files, allow for a "static" site. Been thinking about some core patches for D7 that would make this less of an issue in the future. Also if you know of any other modules that call drupal_clear_js_cache() or drupal_clear_css_cache(), that help would be appreciated.

#1

mikeytown2 - May 31, 2009 - 09:28
Status:active» needs review

This patch at least provides a workaround to the issue

AttachmentSize
googleanalytics.module.patch 403 bytes

#2

hass - June 6, 2009 - 22:30
Status:needs review» needs work

This may not work and create duplicate function names.

You need to think about user having caching enabled and disable the setting tomorrow. Then the file may be aggregated and additional the file is loaded from the remote site. Than all functions are defined twice. We can only solve this by clearing the cache in form save if the cache setting have changed. Should be an addition the current patch only.

#3

mikeytown2 - June 7, 2009 - 00:01
Status:needs work» needs review

How does the above patch create duplicate function names? Main concern is googleanalytics_cache is set to false and googleanalytics_cron() still clears the file/js dir. The above patch prevents this.

Your concern about the setting getting switched on and off valid. Would something like this inside googleanalytics_admin_settings_form_validate() work?

<?php
 
// Clear aggregated JS files if required
 
if ($form['values']['googleanalytics_cache'] != variable_get('googleanalytics_cache', 0)) {
   
drupal_clear_js_cache();
  }
?>

AttachmentSize
google_analytics-477830.patch 1.79 KB

#4

hass - June 7, 2009 - 00:08

Not duplicated PHP functions, but duplicated JS functions. If the function is named foo_track() it's in google.com/*/ga.js (remote) and local /files/googleanalytics/ga.js aggregated into 64asdas7ed1vx.js with all other JS files together. Therefore the JS function exists twice in the pages JS files. If we turn off local caching we need to clean the cache on save, not via cron only.

#5

mikeytown2 - June 7, 2009 - 00:20

Thinking about this more, what if we do a MD5 of the downloaded file as well, so it clears the files/js folder only when google changes theirs.

#6

hass - June 7, 2009 - 17:47

Hm... generally - why not, but it may create another variable. We could save the file with the md5 hash to obfuscate the file name ga.js by this way, too. But we need to clean up the cache folder on cron run. I have never investigated how core cleans up the css/js cache folders with it's bunch of files.

#7

mikeytown2 - June 7, 2009 - 17:52

it just nukes the css/js dirs. Just opened an issue so it will be smarter in the future #484524: Hook for file caches.

<?php
function drupal_clear_js_cache() {
 
file_scan_directory(file_create_path('js'), '.*', array('.', '..', 'CVS'), 'file_delete', TRUE);
 
variable_set('javascript_parsed', array());
}
?>

which cache folder needs to be clear on cron, googleanalytics/?

#8

hass - June 7, 2009 - 19:47

The core JS cache folder (if JS files are have been aggregated) and the files/googleanalytics folder (if local GA caching is enabled). I think files/googleanalytics needs to be cleared first and the others afterwards. Also do not forget hook_disable()...

#9

hass - July 13, 2009 - 06:41
Status:needs review» needs work

@mikeytown2: Are you working on a better patch or should we close this case?

#10

mikeytown2 - July 13, 2009 - 07:26

@hass I'm busy with the boost module. You know what else needs to be done (only clear aggregated if md5 changed & hook_disable), I don't have the time to fix this 100%.

#11

hass - July 13, 2009 - 08:50

I'm also busy with linkchecker, but the next ga release is very close (1-2 weekends) and I do not care much if this task get solved or not.

 
 

Drupal is a registered trademark of Dries Buytaert.