Giter Club home page Giter Club logo

flipzoommedia / processwire-aiom-all-in-one-minify Goto Github PK

View Code? Open in Web Editor NEW
31.0 31.0 26.0 366 KB

AIOM+ (All In One Minify) is a ProcessWire module to easily improve the performance of your website. By a simple function call Stylesheets, LESS and Javascript files can be parsed, minimized and combined into one single file. This reduces the server requests, loading time and minimizes the traffic. In addition, the generated HTML source code can be minimized and all generated files can be loaded over a cookieless domain (domain sharding).

License: MIT License

PHP 100.00%

processwire-aiom-all-in-one-minify's Introduction

#AIOM+ (All In One Minify)#

####Simple minify and parsing for CSS, LESS, JS and HTML####

AIOM+ (All In One Minify) is a ProcessWire module to easily improve the performance of your website. By a simple function call Stylesheets, LESS and Javascript files can be parsed, minimized and combined into one single file. This reduces the server requests, loading time and minimizes the traffic. In addition, the generated HTML source code can be minimized and all generated files can be loaded over a cookieless domain (domain sharding).


####Information####

  • All paths are relative to the template folder. URLs in css files will be automatically corrected. Nothing needs to be changed.
  • If you make changes to the source stylesheet, LESS or javascript files, a new parsed and combined version is created automatically.
  • All parameters can be adjusted via the backend.
  • During development, you can enable developer mode. Files are parsed and combined, but not minimized and browser caching is prevented.
  • You can use the short syntax AIOM or use the full class name AllInOneMinify in your templates.
  • The generated files can be delivered via a subdomain (Domain sharding / Cookieless domain)
  • LESS files can directly server side generated on the fly, without plugins. AIOM+ has a complete, high-performance PHP ported LESS library of the official LESS processor included!
  • NOTE: There are a few unsupported LESS features:
    • Evaluation of JavaScript expressions within back-ticks (for obvious reasons)
    • Definition of custom functions
  • Conditional loading of files based on a API selector

##Table of content##

##Installation##

  1. Copy the files for this module to /site/modules/AllInOneMinify/
  2. In admin: Modules > Check for new modules.
  3. Install Module "AIOM+ (All In One Minify) for CSS, LESS, JS and HTML".

Alternative in ProcessWire 2.4

  1. Login to PW backend and go to Modules
  2. Click tab "new" and enter Module Class Name: "AllInOneMinify"
  3. Click "Download and Install"

##Minimize Stylesheets and parse LESS files##

Minimization of a single file.

<!-- CSS Stylesheet -->
<link rel="stylesheet" type="text/css" href="<?php echo AllInOneMinify::CSS('css/stylesheet.css'); ?>">

<!-- LESS file -->
<link rel="stylesheet" type="text/css" href="<?php echo AllInOneMinify::CSS('css/stylesheet.less'); ?>">

Minimize multiple files into one file. You can even mix stylesheet and LESS files in parsing and combining process!

<link rel="stylesheet" href="<?php echo AllInOneMinify::CSS(array('css/file-1.css', 'css/file-2.less', 'css/file-3.css', 'css/file-4.less')); ?>">

Tip: You can also use the short syntax "AIOM". For example, AIOM::CSS().

##LESS variables access in multiple files##

You have a LESS file in which you are defining, for example, all colors and another LESS file that defines the actual layout? Now you need in the layout LESS file access to the variables of the color LESS file? It's easier than you think. Through a simple referencing of source LESS file. For example:

<link rel="stylesheet" type="text/css" href="<?php echo AllInOneMinify::CSS('css/color.less'); ?>">
...
<link rel="stylesheet" type="text/css" href="<?php echo AllInOneMinify::CSS('css/layout.less'); ?>">

Example content of color.less

@my-color: #ff0000;

Example content of layout.less

@import (reference) "css/color.less";

body {
    background-color: @my-color;
}

That's all. Pretty, hu? The full documentation of LESS you can find at: www.lesscss.org

##Minimize Javascripts##

Minimization of a single file.

<script src="<?php echo AllInOneMinify::JS('js/javascript.js'); ?>"></script>

Minimize multiple files into one file.

<script src="<?php echo AllInOneMinify::JS(array('js/file-1.js', 'js/file-2.js', 'js/file-3.js', 'js/file-4.js')); ?>"></script>

Tip: You can also use the short syntax "AIOM". For example, AIOM::JS().

##Conditional loading##

Since AIOM+ version 3.1.1 javascripts, stylesheets and LESS files can be loaded based on a API selector. Here is an example of conditional loading:

<?php $stylesheets  = array('css/reset.css',
                            'css/main.less',
					        array('loadOn'  => 'id|template=1002|1004|sitemap', 
						          'files'   => array('css/special.css', 'css/special-theme.less'))); ?>
						          
<link rel="stylesheet" type="text/css" href="<?php echo AllInOneMinify::CSS($stylesheets); ?>" />

The same you can do with AIOM::JS(). loadOn must be an ProcessWire API selector.

##Directory Traversal Filter##

By default, only files can be included, which are in ProcessWire template folder. If you wish to add files outside that folder, you have to activate the backend "Allow Directory Traversal" option. Then you can jump back in the path. For example:

AIOM::CSS('../third-party-packages/package/css/example.css');

All paths are still automatically corrected!

##Already minimized files no longer minimized##

To further enhance the performance and to give you maximum flexibility in the combining process, you now have the option to exclude certain files from the minimization (since version 2.2). All files that have the abbreviation ".min" or "-min" at the end of the file name and before the file extension, are no longer minimized. For example: file-1.js is minimized. file-1-min.js or file-1.min.js is not minimized. The same for CSS. file-1.css is minimized. file-1-min.css or file-1.min.css is not minimized.

##Exemplary template structure##

site/
    templates/
        css/
        js/

##Minimize HTML##

The generated HTML source code is automatically minimized when rendering. This requires no change to the templates. Conditional Comments, textareas, code tags, etc. are excluded from the minimization.

NOTE: AIOM+ removes all whitespaces between two tags. If you explicitly need a whitespace, change the whitespace into an HTML entity: &nbsp;. See (#6)

##Development mode##

If you are currently in development of the site, caching can be a problem. For this, you can enable the development mode since version 1.1.0 in the Backend (Module > AIOM > Config). The files will be combined, but not minimized and re-generated at each call. In addition, a no-cache GET parameter is appended with a timestamp to prevent the browser caching. For example: css_031ea978b0e6486c828ba444c6297ca5_dev.css?no-cache=1335939007

##Changelog##

3.2.3

  • Typo fix in variable (Tanks to SteveB)

3.2.2

  • Security Fix: CHMOD (#44)
  • Bugfix: MD5 hash with many files (#46)
  • Improvement in the detection of file changes

3.2.1

  • Bugfix: $config->scripts was not included properly
  • Support for @-webkit-keyframes added

3.2

  • New CSS Compressor: AIOM now uses YUI Compressor (thanks to hwmaier)
  • You can now use $config->scripts and $config->styles in AIOM (#31)
  • Bugfix: Empty {} brackets will only be partly removed (#23)
  • Bugfix: CSS pseudo classes will be compressed incorrectly (#33)

3.1.5

  • Bugfix: Links to images, which are embedded in CSS, are broken if the DOCUMENT_ROOT is not equal to ProcessWire root.

3.1.4

  • Bugfix: CacheFiles for Pages are now deleted when a new minimized file is created
  • Bugfix: An error is thrown if the document root is different to ProcessWire's base path
  • Note: AIOM is now also developed by Conclurer.

3.1.3

  • New LESS version: Update parser to version 1.7.1
    • improved parser exceptions with invalid less
    • prevent fround() from changing integer into double
    • prevent fatal error with preg_match()
    • fix undefined variable
  • New CSSMin version: Update script to version 1.1.2
    • Some improvements
    • Bugfix: Broken rule for firefox 27.0.1 (Animation second "s" lost)
  • Push to stable

3.1.2

  • New feature: Enable or disable directory traversal filter in backend (#12)
  • New LESS version: Update parser to Version 1.7

3.1.1

  • New feature: Conditional loading
  • Update readme / documentation

3.0.1

  • BugFix (#11): Wrong class order in Less.php parser (Thanks to Ryan Pierce)

3.0.0

  • AIOM+ tested with ProcessWire 2.4
  • Module now multilingual
  • New feature: LESS support (direct parsing and minimization server side on the fly)
  • Update readme / documentation

2.2.2

  • BugFix (#8): Many errors if debug mode is activated (Thanks to JoZ3)
  • Better error handling
  • Additional information about spaces in the HTML minimization. See (#6) (Thanks to philippreiner)

2.2.1

  • Code Corrections / class name

2.2.0

  • New feature: File is not minimized when ".min" or "-min" is at the end of the filename. For example: file-1.min.js.
  • Update CSSMin library to Version 1.1 (inspired by Yahoo! YUI compressor)
  • Update JSMin library to Version 2.7.1 (Security fix, recommended update)
  • Performance improvements on first minification

2.1.1

  • Old code removed
  • Cleanup

2.1.0

  • New CSS minimization library
  • Performance improvements

2.0.0

  • Configurable backend (Prefix, lifetime, dev-mode and tips)
  • Empty cache on the backend
  • Domain sharding / cookieless domain
  • Domain sharding for SSL
  • Performance improvements
  • Quick introduction in the backend
  • Performance tips in the backend
  • .htaccess instructions for domain sharding in the backend

1.1.1

  • CSS filter update

1.1.0

  • BugFix (#1): Error: Exception: RecursiveDirectoryIterator ... Permission denied (Thanks to JoZ3 and Ryan)
  • New Short-Syntax AIOM::CSS(); and AIOM::JS();
  • New default settings for css minify (speed up minimizing)
  • New option: enable/disable HTML minify
  • New option: enable/disable development mode (combine but no minimizing)
  • Some optimizations

1.0.0

  • Initial release

##Questions or comments?##

For any questions, suggestions or bugs please create a ticket on GitHub.

##Old stable Version needed?##

Under the following link you can find the old stable version of AIOM without LESS support: https://github.com/conclurer/ProcessWire-AIOM-All-In-One-Minify/tree/AIOM-(old-Stable-2.2.2)

Analytics

processwire-aiom-all-in-one-minify's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

processwire-aiom-all-in-one-minify's Issues

HTML minify removes space character between HTML tags

I have a script like this:

echo "<p><strong>Label:<strong> <span>Text</span></p>"

The space between the <strong> and the <span> tags is deliberate and should be preserved as a literal space character in the paragraph.
But when the "HTML minify" option is on the space character between these tags is stripped out.
The same problem occurs if I have an <a> tag after my <strong> tag.

Feature request: Preserve special comments like /*! ... */

Some comments must not be removed from CSS for copyright/license reasons. Most other compression tools leave such comments intact once they are tagged with an explanation mark.

/*!  This comment is not removed */

I would suggest to add this feature to AIOM, I could provide a patch to the comment regex.

HTML minification RegEx causing stack overflow in Apache.

I was getting a connection reset error on every page load with no errors logged anywhere. It took me a while to locate the exact line, I had to keep moving an exit() call around until I found the offending piece of code.

Of course this can be solved by increasing the stack size, but so this plugin can be used in more limited environments, it might be worth not using a big regular expression, and instead opting for a different technique (seen here).

I modified AIOM to use this method, and it seems to do a better job of HTML minification as it also minifies inline styles and scripts. Though there are a couple of issues with it removing conditional comments, I think it's still worth looking into.

Print css content as inline

With the introduction of AMP technology by google, i would know if is possible to print the generated css as inline element instead of using link tag, because in AMP spec this tag aren't allowed for css but only for fonts.

Best regards

css calc

is there a way to keep spaces in css calc for the code to work?

Licence violation: AIOM incorporates non-free software

You may not know this, but by installing AIOM into Processwire site, any such deployment or project effectively becomes non-free due to the usage of JSMin.php.

A description of the issue is given in this article (see section "JSMin, freedom, and the JSON License")

Theoretically any website could be taken down, should Mr. Crockford deem it "evil" - which is unlikely to happen, but still, considering JSMin is an abandoned project, #27 should be given a higher priority - i'd actually consider releasing it in a minor release rather than waiting for AIOM 4.

Directory Traversal option wrong logic?

$_path  = (self::$directoryTraversal !== true) ? str_ireplace(array('../', './', '%2e%2e%2f', '..%2F'), '', wire('config')->paths->templates.$_file) : wire('config')->paths->templates.$_file;

This is true when the option is disabled,

self::$directoryTraversal   = ($this->directory_traversal == 1) ? true : false;

If option to traverse files is enabled (checkbox) the "self::$directoryTraversal" will be "true"

Do I miss something?

Can't create combined CSS file with HTTPS sites

Occured on ProcessWire 2.3.8 (also tested with 2.3.5) dev using the latest (2.2.1) AIOM module.

I'm forcing HTTPS for the whole site, by setting the URL on the home template to "HTTPs only". After doing this, the creation of a new combined file fails. If I switch back to HTTP and open the site via the http:// url to generate the combined file it works. Enabling HTTPs afterwards without any changes to the CSS/JS works too.

To summarize:
HTTPS, new CSS -> AIOM fails
HTTP, new CSS -> AIOM works
HTTPS after HTTP, no changes to CSS -> AIOM works until CSS/JS Change.

I'm getting this error:
Exception: The combined css cache file could not be created. (in /home/httpd/vhosts/***/site/modules/AllInOneMinify/AllInOneMinify.module line 517)

Permission 0777 not safe in some environments

Thanks for this module. I was just implementing here for a client, and noticed it using hard-coded 0777 permission rather than ProcessWire's $config->chmodDir and $config->chmodFile. The server I'm working with is a typical shared server, where 0777 for dirs (0666 for files) is not safe because it means other users on the server and modify the files. The same is true in many hosting environments. I was wondering if you would consider using the PW config properties I mentioned above instead, or just use PW's wireChmod('/path/to/dir/or/file'); which automatically makes them writable consistent with the PW configured settings. Assuming those PW settings are configured properly, this ensures the safety of any writable directories or files.

If file list are longer than 32 chars. this function (_getCacheName) not working, and system loading old compiled file

If file list are longer than 32 chars compile not working. If there is a file compiled until 32 chars, AIOM loading this file.
Here is my usage example :

$scripts  = array(
        'styles/bower_components/jquery/dist/jquery.min.js',
        'styles/bower_components/lazysizes/lazysizes.min.js',
        'styles/bower_components/uikit/js/uikit.min.js',
        'styles/bower_components/uikit/js/components/tooltip.min.js',
        array(
            'loadOn'  => 'template=home|reference',
            'files'   => array(
                'styles/bower_components/uikit/js/components/slideshow.min.js'
            )
        ),
        array(
            'loadOn'  => 'template=home|basic-page',
            'files'   => array(
                'styles/bower_components/uikit/js/components/slideset.min.js'
            )
        ),
        array(
            'loadOn'  => 'template=basic-page|reference',
            'files'   => array(
                'styles/bower_components/uikit/js/components/lightbox.min.js'
            )
        ),
        array(
            'loadOn'  => 'template=reference-list',
            'files'   => array(
                'styles/bower_components/uikit/js/components/grid.min.js'
            )
        ),
        array(
            'loadOn'  => 'template=reference',
            'files'   => array(
                'styles/comments.js'
            )
        ),
        'styles/init.js'
    );

if you remove md5 timestamp conversion its ok. Check MD5 -> http://php.net/md5

private static function _getCacheName($files, $prefix = 'css_', $ext = '.css') {
        // ------------------------------------------------------------------------
        // Initialize timestamp variable.
        // ------------------------------------------------------------------------
        $_timestamp = '';

        // ------------------------------------------------------------------------
        // Combine all timestamps to one string.
        // ------------------------------------------------------------------------
        foreach ($files as $file) {
            $_timestamp .= $file['last_modified'];
        }

        // ------------------------------------------------------------------------
        // Create a unique MD5 file name with the specified prefix.
        // ------------------------------------------------------------------------
        return (self::$developmentMode !== true) ? $prefix.md5($_timestamp).$ext : $prefix.md5($_timestamp).'_dev'.$ext;
    }

Bootstrap 4 SVG spacings removed causing non display

SASS:
$custom-checkbox-indicator-icon-checked: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'><path fill='#{$custom-control-indicator-checked-color}' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z'/></svg>") !default;

MINIFIED (Spaces removed - Not Working):
url("data:image/svg+xml,%3csvgxmlns='http://www.w3.org/2000/svg'width='8'height='8'viewBox='0088'%3e%3cpathfill='%23fff'd='M6.564.75l-3.593.612-1.538-1.55L04.26l2.9742.99L82.193z'/%3e%3c/svg%3e")

EXPCETED (Works):
url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%23fff' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z'/%3e%3c/svg%3e")

images into css nof found, error 404

A issue with the path of the images into the css file when pw is installed in a subdirectory, example:

the correct file path output without AIOM+

http://localhost/mysite/site/templates/images/image.jpg

file path output with AIOM+ enable

http://localhost/site/templates/images/image.jpg

this generate 404 error, file not found.

I tried to fix changing the RewriteBase in .htaccess enabling my localhost subdirectory

RewriteBase /mysite/

but the same error still happens if I turn off the AIOM + and use the url from the css file works without any inconvenience..

Google Webfonts @import

Hi David,

This is a great module but I have a small issue when using it. Iif I link to a Google webfont in my CSS (via @import) it doesn't display at all.

Regards
Marty

AIOM Cache conflict with ProcessWire's Page Render Cache

AIOM seems to conclict with ProcessWire Core's cache. In AIOM I have set Lifetime to 2419200 for my CSS and JS files. In ProcessWire, I cache the pages -- here: Templates > Go to the Cache tab. and set Cache Time to 86400 (24 hours).

The reason for this issue is that AIOM updates the file name for the cached CSS and JS files while ProcessWire's Page Render cache does not update the file names simultaneusly.

File names cached by ProcessWire's Page Render Cache (in my case, these files do not exist to end-users / 404):

For instance, these file names were shown to me because I was logged in (valid files / 200):

<link rel="stylesheet" href="/site/assets/aiom/css_e4c680d6b59866248e0dc0a3317324a0.css">
<script src="/site/assets/aiom/js_cde06f61b83de6205615a30c87616efd.js"></script>

... and these were the file names presented to the end-user (the files did not exist / 404):

<link rel="stylesheet" href="/site/assets/aiom/css_xxxxxxxxxxxxxxxx999999999999.css">
<script src="/site/assets/aiom/js_xxxxxxxxxxxxxxxx999999999991.js"></script>

My workaround was to copy the contents of the AIOM files into static files outside the AIOM folder -- since this will allow cached PW-files to always point at the correct CSS/JS file. Example:

<link rel="stylesheet" href="/site/assets/style.css">
<script src="/site/assets/js_top.js"></script>
<script src="/site/assets/js_bottom.js"></script>

CacheFile for Pages - PW3 issue, and ClearCacheFromBackend problem

Hi
I got two problems that all have to do with the Processwire Template Cache when using AIOM.

1) First of the ClearCacheFromBackend issue:
Following initial situation:

  • I have the template cache enabled and pages are in the cache
  • I have AIOM Files in the cache
  • Now Goto AIOM Config Screen and click "Empty Cache" (/module/edit?name=AllInOneMinify).
  • Then Goto to the Frontend (with a non logged in browser) on a page where TemplateCache should be active.
  • The CSS and JS Files are not there anymore and breaks the layout.

In the AllInOneMinify::ClearCacheFromBackend Funtion there is no direct removal of the cache files. On cached Version in Frontend AIOM never reaches the point where the CacheFiles would be deleted, wich is
here for JS and here for CSS:

If i am adding this code in ClearCacheFromBackend after self::_clearCache(true); here

$pageRender = wire('modules')->PageRender;
if($pageRender) {
   CacheFile::removeAll(wire('config')->paths->cache.PageRender::cacheDirName."/");
}

this issue is removed.
Can anyone confirm this?

2) The second Problem
has a direct relation to this, so I post it here.
When using AIOM in PW3 I think the class_exists function used for checking if PageRender exists never returns true.

This has todo with Namespaces in PW3 I guess (see php.net comment). Also the compiled FileCompiler Version does not add anything to the class_exists call. However, I am wondering it this if statement with class_exists is needed anyway. Beacause PageRender cannot be uninstalled, it should always be there. Perhaps I´m missing something here? Another way of checking without class_exists would be the way I do it in the Example above.

I hope that someone can confirm this issues and write back. I had two sites broken in the last week. I don´t know exactly what happened that AIOM FileCache got cleared in the backend, but with this simple solution it should not happen anymore...

I can make a pull request if this helps...
thanks

error after installed

This error happend after install:

Error: Exception: RecursiveDirectoryIterator::__construct(/home/myserver/public_html/mysite/site/assets/aiom/) [recursivedirectoryiterator.--construct]: failed to open dir: Permission denied (in /home/myserver/public_html/mysite/site/modules/AllInOneMinify/AllInOneMinify.module line 408)

This error message was shown because you are logged in as a Superuser. Error has been logged.

Error when debug mode enable in config.php

I have this error when debug mode is true and the module not work...


Strict Standards: Non-static method AllInOneMinify::JS() should not be called statically, assuming $this from incompatible context in /home/myserver/public_html/mysite/site/templates/main.php on line 138

Strict Standards: Non-static method AllInOneMinify::_fileArray() should not be called statically, assuming $this from incompatible context in /home/myserver/public_html/myserver/public_html/mysite/site/modules/AllInOneMinify/AllInOneMinify.module on line 231

Strict Standards: Non-static method AllInOneMinify::_getCacheName() should not be called statically, assuming $this from incompatible context in /home/myserver/public_html/demos/hotelkahve/site/modules/AllInOneMinify/AllInOneMinify.module on line 232

Notice: Undefined variable: _timestamp in /home/myserver/public_html/demos/hotelkahve/site/modules/AllInOneMinify/AllInOneMinify.module on line 448

/mysite/site/assets/aiom/js_27a4aa3dfbfbe40ad50d2f177f91e918.js">

Why static calls?

I find it strange how the module is built and the way it is setup I can't for example overwrite a config var on runtime... cause all is static?

I.e: stuff like
$modules->AllInOneMinify->development_mode = true;

Or why is the module autoload? 'autoload' => true,

It means it load even if there's no call for any of AIOM in templates. A on demand loading would be much better.

$aiom = $modules->AllInOneMinify;

echo $aiom->CSS();

Debug mode results in "Division by zero" error

When turning debug mode on, the stylesheet does not get parsed correctly and gives this error in the page's head:

"Division by zero in .../site/modules/AllInOneMinify/lib/Less/Less.php on line 2896"

When debug mode is off in ProcessWire, things run just fine. Please let me know what other information I can provide.

PHP 7.1 Compatibility

Upon using AIOM in a PHP 7.1 environment, I am now seeing several warnings and notices appearing.

Warning: A non-numeric value encountered in AllInOneMinify.module on line 713

Upon further inspection, the variable $_timestamp is initialised as '' rather than 0. Therefore the new notices that PHP issues when arithmetic is performed on non numeric values pop up.

The other error I saw is:

Notice: A non well formed numeric value encountered in cssmin.php on line 769

Upon further inspection, I can see that the variable $size is an integer in the form of a string, and is sometimes suffixed with a unit. That unit is not removed before $size is implicitly casted to an integer during the arithmetic seen on that line.

None of issues actually cause any real problems, it's just nice knowing that there are no errors being issued whatsoever.

domain sharding not working over https

hi i just install new ssl to my site and sub domain, and then i activate domain sharding option change url to https subdomain and then i clear all the template cache, module cache, compile files but https domain sharding url not printing. the module only print http domain sharding url not https, how can i solve this.

CSS compression bug with :hover

The seems to be a bug with the CSS compression.

#nav :hover{}

becomes when compressed:

 #nav:hover{}

The blank should not be removed as it is a separator between a parent and a child element and removing it changes the cascade!

The the first rule identifies a child element of a #nav element which is hovered over like the anchor link in this HTML snippet:

<div id="nav"><a href="/">I am a hovering child element</a><div>  

and the latter identifies just the #nav element itself which is hovered over like:

<div id="nav"> I am a hovering parent element. My children don't matter. <div>  

As a consequence this bug breaks CSS based menus.

Minify HTML option empties inline <script>

I have inline scripts for banners, they are not working when using HTML Minify option.

<script>content gets removed</script>

BTW are you still maintaining this module? It's the most liked on modules.processwire.com, but haven't heard anything since a long time.

Compiled files are empty

AOIM is generating CSS and js files but they're coming up blank (except for a comment if I turn on dev mode).

The site is running PW 2.4 and I'm using AOIM 3.1.3.

Files are in a folder outside my templates directory but I've turned on directory traversal.

I've also got HTML minify turned on but it's not minifying.

SASS support in AIOM?

Are there any plans to add SCSS support to AIOM?
I saw that Bootstrap 4 will be using Sass instead of Less.

I think it would be a great feature to add SASS Support. There is already a PHP SASS Compiler out there... http://leafo.net/scssphp/

anyway, thanks for this great module!

[BUG] AllInOneMinify::_getFileInfoArray():751

on line 751 You should not replace "../" dir to "". It had different meaning with "./"

// Fix Error, you should not replace "../" to ""
        //$_path  = str_ireplace(array('../', './', '%2e%2e%2f', '..%2F'), '', (wire('config')->paths->templates.$_file));
        $_path  = wire('config')->paths->templates.$_file;

Feature Request: Concatenate first, then compile.

I'd love to see an option to switch the order of operations so that watched .less files are concatenated first, then compiled. It's easier to maintain larger projects if you can just add a new library file in the correct position and not have to worry about @importing it in every file that depends on it.

Feature Request: Create multiple packages

At times it's advantageous to group code into multiple packages, for example when one page of a site contains a lot of extra code that is only needed on that one page. Is it possible to use AIOM to produce a separate package for each of these?

Rewriting error when PWdocRoot != ServerDocRoot

Hi there,
as my Processwire installation is in a subdirectory and under a subdomain, I came across a problem where all URIs in the minified CSS file were wrong. The problem is that my $_SERVER['DOCUMENT_ROOT'] differs from the document root of my processwire.

docRoot of PW: /home/htdocs/processwire
$_SERVER['DOCUMENT_ROOT']: /home/htdocs

URIs in CSS as they are /processwire/site/templates/styles/images/image.jpg
URIs in CSS as they should be /site/templates/styles/images/image.jpg

The Rewrite-Function in site/modules/AllInOneMinify/lib/UriRewriter.php uses the docRoot as third parameter. But in line 573 of AllInOneMinify.module there is no third parameter given, resulting in the Rewrite-Function to use $_SERVER['DOCUMENT_ROOT'] as value.

So after changing line 573 of AllInOneMinify.module from

$_css_src = (!empty($_css_src)) ? Minify_CSS_UriRewriter::rewrite($_css_src, dirname($stylesheet['absolute_path'])) : $_css_src;

to

$_css_src = (!empty($_css_src)) ? Minify_CSS_UriRewriter::rewrite($_css_src, dirname($stylesheet['absolute_path']),wire('config')->paths->root) : $_css_src;

everything worked as expected. :-)

Suggestion: conditional loading

As always, thank you very much for your work with this module, I am using it in every project I'm working on. would be interesting to have the option to upload each file conditionally, eg:

where [id] is the ID of the page, without the [id] would load on all pages.

SourceMap

For Developer Mode would be nice
suggest for line 604

if(self::$developmentMode === true) $options = array( 'sourceMap' => true );
$_less_parser   = new Less_Parser($options);

css minify script issue with removing empty {}

In the CSSMin php
// ------------------------------------------------------------------------
// Remove empty blocks.
// ------------------------------------------------------------------------
// $_source = preg_replace('/}[^\/}]+{}/', '}', $_source);

I had to comment out because I like to have some media query in some css empty while developing. The removing of the empty brackets lead to unexpected results with "open" media queries.

Allow for absolute file paths...

It would be nice to be able to use modules with styles/scripts and absolute paths from /site/.

I've tested something like this and seems to be working fine:

private static function _getFileInfoArray($_file, $extension) {

        if(strpos($_file, "/site") === 0){
            $_path = wire('config')->paths->root. ltrim($_file,"/");
        } else {
            // ------------------------------------------------------------------------
            // Filter Directory Traversal (default: yes)
            // ------------------------------------------------------------------------
            $_path  = (self::$directoryTraversal !== true) ? str_ireplace(array('../', './', '%2e%2e%2f', '..%2F'), '', wire('config')->paths->templates.$_file) : wire('config')->paths->templates.$_file;
        }

....

Incorrect re-use of CSS-file

The function _getCacheName uses the last_modified timestamp to generate a unique filename.

In my case, I use the same LESS files for 2 different page templates, except for 1 LESS file (which depends on the page template used). So I should get a different CSS file in this template.
But unfortunately the 2 LESS files that differ have exactly the same last_modified timestamp, so the same filename is generated for the CSS file. This results in incorrect classes in the CSS file included in 1 of the pages.

Relative @import in .less files not working in hosted environment

When feeding a less file to AIOM that includes an @import for another .less file in the same directory, less compilation fails, producing the following ending output in the generated css file:

#_____LESS_____ERROR_____REPORT_____ {content:"File `/site/templates/styles/phone.less` not found. in anonymous-file-0.less"}

The problem only occurs on the live server, which is a shared hosting environment with a virtual host, whilst my local environment does not employ a virtual host. The same live environment also suffers from bug #38

Both problems occur whenever DOCUMENT_ROOT (which is used by Minify_CSS_UriRewriter::rewrite) is different from wire('config')->paths->root (which always gives the accurate position of files).

Related issues:

I have now fixed and tested both issues locally and will send a PR shortly.

Cache filename collision

If an array of filenames are passed, and all files have the same modified timestamp on separate pages a collision will occur and the wrong file is served for subsequent pages.

eg: Page 1 - array('file1.js','file2.js');
Page 2 - array('file1.js','file3.js');

Each file has the same timestamp (ie; rsync or similar copy operation).

Simple fix:
$_timestamp = ($_timestamp + $file['last_modified'] . basename($file['absolute_path']));

CSS images not found when PW running in subfolder

When PW is not running in the domain's root folder, but in a subfolder (ie. /dev) the minified relative css image location points to the root instead of the subfolder.

Example:

AIOM 3.2.1 tries to find the images in http://mydomain.com/site/templates/img

PHP 7.3 Compatibility

With PHP 7.3.0 (Windows), AllInOneMinify 3.2.3, ProcessWire 3.0.123, I get the following Continue Targeting Switch Warning (path parts snipped):

Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9387
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9395
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9400
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9406
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9416
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9419
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9439
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9444
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9465
Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in \site\assets\cache\FileCompiler\site\modules\AllInOneMinify\lib\Less\Less.php on line 9472

I have not tried the fork mentioned in #65 , maybe this has been fixed there too.

Wrong class order in Less.php parser

If a large LESS file is split by the parser, the following error occurs:

"Error: Class 'Less_Exception_Parser' not found (line 8795 of /site/modules/AllInOneMinify/lib/Less/Less.php)"

Issue found and submited by Ryan Pierce. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.