Download & Extend

Refactor local file caching and cache clear logic

Project:Google Analytics
Version:6.x-3.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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.

Comments

#1

Status:active» needs review

This patch at least provides a workaround to the issue

AttachmentSizeStatusTest resultOperations
googleanalytics.module.patch403 bytesIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch googleanalytics.module_3.patch.View details

#2

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

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();
  }
?>
AttachmentSizeStatusTest resultOperations
google_analytics-477830.patch1.79 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch google_analytics-477830.patch.View details

#4

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

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

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

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

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

Status:needs review» needs work

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

#10

@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

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.

#12

Status:needs work» closed (won't fix)

No patch for about 1 year. Closing inactive task.

#13

Version:6.x-2.x-dev» 6.x-3.x-dev
Status:closed (won't fix)» needs review

Patch only resets the cache if Google changes it's file or checksums do not match. Check is done every 24 hours as before, and caching has been optimized.

AttachmentSizeStatusTest resultOperations
D6_ga_clear_js_cache.patch4.22 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch D6_ga_clear_js_cache.patch.View details

#14

Title:googleanalytics_cron() calling drupal_clear_js_cache() & boost» Refactored local ga.js caching and refresh logic

#15

AttachmentSizeStatusTest resultOperations
D6_ga_clear_js_cache.patch4.22 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch D6_ga_clear_js_cache_0.patch.View details

#16

Title:Refactored local ga.js caching and refresh logic» Refactor local file caching and cache clear logic
Status:needs review» fixed

#17

awesome, thanks for doing this.

#18

Commited followup as I've seen there is no longer a need to clear the JS caches at all as ga.js is not aggregated anymore with core files since async version.

#19

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.