Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
continuous scrolling carousels
#7
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 +
Reply


Messages In This Thread
continuous scrolling carousels - by Felix - 2020-09-14, 04:08:35
RE: continuous scrolling carousels - by zekoolweb - 2020-09-20, 20:55:06
RE: continuous scrolling carousels - by Felix - 2020-09-21, 00:27:05
RE: continuous scrolling carousels - by Felix - 2020-09-21, 20:16:16
RE: continuous scrolling carousels - by zekoolweb - 2020-09-21, 21:50:36
RE: continuous scrolling carousels - by Felix - 2020-09-21, 21:58:22
RE: continuous scrolling carousels - by Felix - 2020-09-24, 17:12:16
RE: continuous scrolling carousels - by Felix - 2020-09-24, 17:28:33



Users browsing this thread: 1 Guest(s)