Skip to content

Commit

Permalink
Issue #2571481 by slydevil, Dom.: Locally cached file is not gzipped
Browse files Browse the repository at this point in the history
  • Loading branch information
Miroslav authored and Jen Lampton committed Jan 13, 2021
1 parent 3ae6cec commit 174766e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion googleanalytics.module
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function googleanalytics_preprocess_layout() {
$library_tracker_url = 'https://www.google-analytics.com/' . ($debug ? 'analytics_debug.js' : 'analytics.js');

// Should a local cached copy of analytics.js be used?
if (variable_get('googleanalytics_cache', 0) && $url = _googleanalytics_cache($library_tracker_url)) {
if ($config->get('cache') && $url = _googleanalytics_cache($library_tracker_url)) {
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
// flush, forcing browsers to load a new copy of the files, as the
Expand Down Expand Up @@ -533,6 +533,10 @@ function _googleanalytics_cache($location, $synchronize = FALSE) {
if ($data_hash_local != $data_hash_remote && file_prepare_directory($path)) {
// Save updated tracking code file to disk.
file_unmanaged_save_data($result->data, $file_destination, FILE_EXISTS_REPLACE);
// Based on Backdrop Core backdrop_build_css_cache().
if (settings_get('css_gzip_compression', TRUE) && config_get('system.core', 'clean_url') && extension_loaded('zlib')) {
file_unmanaged_save_data(gzencode($result->data, 9, FORCE_GZIP), $file_destination . '.gz', FILE_EXISTS_REPLACE);
}
watchdog('googleanalytics', 'Locally cached tracking code file has been updated.', array(), WATCHDOG_INFO);

// Change query-strings on css/js files to enforce reload for all users.
Expand All @@ -545,6 +549,10 @@ function _googleanalytics_cache($location, $synchronize = FALSE) {
// There is no need to flush JS here as core refreshes JS caches
// automatically, if new files are added.
file_unmanaged_save_data($result->data, $file_destination, FILE_EXISTS_REPLACE);
// Based on Backdrop Core backdrop_build_css_cache().
if (settings_get('css_gzip_compression', TRUE) && config_get('system.core', 'clean_url') && extension_loaded('zlib')) {
file_unmanaged_save_data(gzencode($result->data, 9, FORCE_GZIP), $file_destination . '.gz', FILE_EXISTS_REPLACE);
}
watchdog('googleanalytics', 'Locally cached tracking code file has been saved.', array(), WATCHDOG_INFO);

// Return the local JS file path.
Expand Down

0 comments on commit 174766e

Please sign in to comment.