Hi,
as mentioned I made a beginning with compressing the css and js scripts,
such as removing comments and white space.
This is useful because it makes a website load even a bit more faster.
This can be easily done with straight forward php,
here is what I have working so far:
Code:
if (return_page_slug()=='index') {
// Example
// 1. For the home page we need screen.css - home.css - gallery3.css
// 2. Create a variable $buffer and initiate it empty
// 3. Load the contents of the css files in the variable $buffer
// 4. Remove comments - empty spaces and white space
// 5. Write the contents of $buffer to a file compressed.css
// 6. Echo out compressed.css like a usual css link in the header
$buffer = "";
$buffer .= file_get_contents(GSROOTPATH . 'theme/Gallery3/assets/css/screen.css');
$buffer .= file_get_contents(GSROOTPATH . 'theme/Gallery3/assets/css/home.css');
$buffer .= file_get_contents(GSROOTPATH . 'theme/Gallery3/assets/css/gallery3.css');
// Remove comments
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
// Remove space after colons
$buffer = str_replace(': ', ':', $buffer);
// Remove space before acolade
$buffer = str_replace(' {', '{', $buffer);
// Remove space after acolade
$buffer = str_replace('{ ', '{', $buffer);
// Remove whitespace
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
$filename = GSROOTPATH . 'theme/Gallery3/assets/css/compressed.css';
file_put_contents ($filename, $buffer);
echo '<link href="' . get_theme_url(false) . '/assets/css/compressed.css"' . ' rel="stylesheet">' . "\n";
Ok, so far so good.
- - - - - - - - - - - - - - - - - -
If anyone knows how to remove white space for the following cases, please let us know:
1) remove white space left from a single quote,
example: ('--animation', 'slide')
2) remove white space left and right from =>
3) remove white space left and right from =
4) remove white space left and right from +