Skip to content

Commit

Permalink
Removed CSS/JS merging, useless since HTTP2
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Nov 16, 2024
1 parent a283064 commit 15aa230
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 486 deletions.
5 changes: 0 additions & 5 deletions app/code/core/Mage/Adminhtml/Block/Cache/Additional.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,4 @@ public function getCleanSwatchesUrl()
{
return $this->getUrl('*/*/cleanSwatches');
}

public function getCleanMediaUrl()
{
return $this->getUrl('*/*/cleanMedia');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ protected function _beforeSave()
return $this;
}

/**
* Clean compiled JS/CSS when updating url configuration settings
*/
#[\Override]
protected function _afterSave()
{
if ($this->isValueChanged()) {
Mage::getModel('core/design_package')->cleanMergedJsCss();
}
return $this;
}

/**
* @inheritDoc
*/
Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions app/code/core/Mage/Adminhtml/controllers/CacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,6 @@ public function massRefreshAction()
$this->_redirect('*/*');
}

/**
* Clean JS/css files cache
*/
public function cleanMediaAction()
{
try {
Mage::getModel('core/design_package')->cleanMergedJsCss();
Mage::dispatchEvent('clean_media_cache_after');
$this->_getSession()->addSuccess(
Mage::helper('adminhtml')->__('The JavaScript/CSS cache has been cleaned.')
);
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addException(
$e,
Mage::helper('adminhtml')->__('An error occurred while clearing the JavaScript/CSS cache.')
);
}
$this->_redirect('*/*');
}

/**
* Clean catalog files cache
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@ public function saveAction()
}
Mage::app()->saveUseCache($enable);

// clean javascript/css cache
if ($this->getRequest()->getPost('jscss_action')) {
if (Mage::getDesign()->cleanMergedJsCss()) {
$this->_getSession()->addSuccess(
Mage::helper('adminhtml')->__('The JavaScript/CSS cache has been cleared.')
);
} else {
$this->_getSession()->addError(Mage::helper('adminhtml')->__('Failed to clear the JavaScript/CSS cache.'));
}
}

/**
* Run catalog actions
*/
Expand Down
100 changes: 0 additions & 100 deletions app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,106 +746,6 @@ public function uniqHash($prefix = '')
return $prefix . md5(uniqid(microtime() . mt_rand(), true));
}

/**
* Merge specified files into one
*
* By default will not merge, if there is already merged file exists and it
* was modified after its components
* If target file is specified, will attempt to write merged contents into it,
* otherwise will return merged content
* May apply callback to each file contents. Callback gets parameters:
* (<existing system filename>, <file contents>)
* May filter files by specified extension(s)
* Returns false on error
*
* @param string|false $targetFile - file path to be written
* @param bool $mustMerge
* @param callable $beforeMergeCallback
* @param array|string $extensionsFilter
* @return bool|string
*/
public function mergeFiles(
array $srcFiles,
$targetFile = false,
$mustMerge = false,
$beforeMergeCallback = null,
$extensionsFilter = []
) {
try {
// check whether merger is required
$shouldMerge = $mustMerge || !$targetFile;
if (!$shouldMerge) {
if (!file_exists($targetFile)) {
$shouldMerge = true;
} else {
$targetMtime = filemtime($targetFile);
foreach ($srcFiles as $file) {
if (!file_exists($file)) {
// no translation intentionally
Mage::logException(new Exception(sprintf('File %s not found.', $file)));
} elseif (@filemtime($file) > $targetMtime) {
$shouldMerge = true;
break;
}
}
}
}

// merge contents into the file
if ($shouldMerge) {
if ($targetFile && !is_writable(dirname($targetFile))) {
// no translation intentionally
throw new Exception(sprintf('Path %s is not writeable.', dirname($targetFile)));
}

// filter by extensions
if ($extensionsFilter) {
if (!is_array($extensionsFilter)) {
$extensionsFilter = [$extensionsFilter];
}
if (!empty($srcFiles)) {
foreach ($srcFiles as $key => $file) {
$fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (!in_array($fileExt, $extensionsFilter)) {
unset($srcFiles[$key]);
}
}
}
}
if (empty($srcFiles)) {
// no translation intentionally
throw new Exception('No files to compile.');
}

$data = '';
foreach ($srcFiles as $file) {
if (!file_exists($file)) {
continue;
}
$contents = file_get_contents($file) . "\n";
if ($beforeMergeCallback && is_callable($beforeMergeCallback)) {
$contents = call_user_func($beforeMergeCallback, $file, $contents);
}
$data .= $contents;
}
if (!$data) {
// no translation intentionally
throw new Exception(sprintf("No content found in files:\n%s", implode("\n", $srcFiles)));
}
if ($targetFile) {
file_put_contents($targetFile, $data, LOCK_EX);
} else {
return $data; // no need to write to file, just return data
}
}

return true; // no need in merger or merged into file successfully
} catch (Exception $e) {
Mage::logException($e);
}
return false;
}

/**
* Return default country code
*
Expand Down
Loading

0 comments on commit 15aa230

Please sign in to comment.