Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Magento JS Speed Fix
Tuesday, December 2nd, 2008 at 11:59:00pm UTC 

  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to [email protected] so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category    Mage
  22. * @package     Mage_Core
  23. * @copyright   Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
  24. * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  25. */
  26.  
  27. /**
  28. * Proxy script to combine and compress one or few files for JS and CSS
  29. *
  30. * Restricts access only to files under current script's folder
  31. *
  32. * @category    Mage
  33. * @package     Mage_Core
  34. * @author      Magento Core Team <[email protected]>
  35. */
  36.  
  37. // no files specified return 404
  38. if (empty($_GET['f'])) {
  39.     header('404 Not found');
  40.     echo "SYNTAX: index.php/x.js?f=dir1/file1.js,dir2/file2.js";
  41.     exit;
  42. }
  43.  
  44. if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
  45. {
  46.     header("HTTP/1.1 304 Not Modified");
  47.     exit;
  48. }
  49.  
  50. $files = is_array($_GET['f']) ? $_GET['f'] : explode(',', $_GET['f']);
  51.  
  52. header('Cache-Control: must-revalidate');
  53. header('Last-modified: ' . gmdate('r'));
  54. header('Content-type: text/javascript');
  55.  
  56. $time = time()+(365*86400);
  57.  
  58. header('Expires: '.gmdate('r', $time));
  59.    
  60. foreach($files as $file)
  61. {
  62.     $p = trim(str_replace('/', DIRECTORY_SEPARATOR, $file), DIRECTORY_SEPARATOR);
  63.  
  64.     // validate file path
  65.     if (empty($p) || strpos($p, '..')!==false || strpos($p, '//')!==false || !file_exists($p)) {
  66.         continue;
  67.     }
  68.  
  69.     // append file contents
  70.     print file_get_contents($p);       
  71.     flush();
  72. }
  73.  

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right