GithubHelp home page GithubHelp logo

samkatakouzinos / autoptimize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from futtta/autoptimize

0.0 2.0 0.0 2.05 MB

Official Autoptimize repo on Github

Home Page: https://autoptimize.com/

License: GNU General Public License v2.0

PHP 97.45% Shell 0.58% HTML 0.08% CSS 1.35% JavaScript 0.55%

autoptimize's Introduction

Autoptimize

The official Autoptimize repo on Github can be found here.

Example use of Autoptimize's API

Filter: autoptimize_filter_css_datauri_maxsize

add_filter('autoptimize_filter_css_datauri_maxsize','my_ao_override_dataursize',10,1);
/**
 * Change the threshold at which background images are turned into data URI-s.
 *
 * @param $urisize: default size
 * @return: your own preferred size
 */
function my_ao_override_dataursize($urisizeIn) {
	return 100000;
}

Filter: autoptimize_filter_css_datauri_exclude

add_filter('autoptimize_filter_css_datauri_exclude','my_ao_exclude_image',10,1);
/**
 * Exclude background images from being turned into data URI-s.
 *
 * @param $imageexcl: default images excluded (empty)
 * @return: comma-seperated list of images to exclude
 */
function my_ao_exclude_image($imageexcl) {
	return "adfreebutton.jpg, otherimage.png";
}

Filter: autoptimize_filter_js_defer

add_filter('autoptimize_filter_js_defer','my_ao_override_defer',10,1);
/**
 * Change flag added to Javascript.
 *
 * @param $defer: default value, "" when forced in head, "defer " when not forced in head
 * @return: new value
 */
function my_ao_override_defer($defer) {
	return $defer."async ";
}

Filter: autoptimize_filter_noptimize

add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
/**
 * Stop autoptimize from optimizing, e.g. based on URL as in example.
 *
 * @return: boolean, true or false
 */
function my_ao_noptimize() {
	if (strpos($_SERVER['REQUEST_URI'],'no-autoptimize-now')!==false) {
		return true;
	} else {
		return false;
	}
}

Filter: autoptimize_filter_js_exclude

add_filter('autoptimize_filter_js_exclude','my_ao_override_jsexclude',10,1);
/**
 * JS optimization exclude strings, as configured in admin page.
 *
 * @param $exclude: comma-seperated list of exclude strings
 * @return: comma-seperated list of exclude strings
 */
function my_ao_override_jsexclude($exclude) {
	return $exclude.", customize-support";
}

Filter: autoptimize_filter_css_exclude

add_filter('autoptimize_filter_css_exclude','my_ao_override_cssexclude',10,1);
/**
 * CSS optimization exclude strings, as configured in admin page.
 *
 * @param $exclude: comma-seperated list of exclude strings
 * @return: comma-seperated list of exclude strings
 */
function my_ao_override_cssexclude($exclude) {
	return $exclude.", recentcomments";
}

Filter: autoptimize_filter_js_movelast

add_filter('autoptimize_filter_js_movelast','my_ao_override_movelast',10,1);
/**
 * Internal array of what script can be moved to the bottom of the HTML.
 *
 * @param array $movelast
 * @return: updated array
 */
function my_ao_override_movelast($movelast) {
	$movelast[]="console.log";
	return $movelast;
}

Filter: autoptimize_filter_css_replacetag

add_filter('autoptimize_filter_css_replacetag','my_ao_override_css_replacetag',10,1);
/**
 * Where in the HTML is optimized CSS injected.
 *
 * @param array $replacetag, containing the html-tag and the method (inject "before", "after" or "replace")
 * @return array with updated values
 */
function my_ao_override_css_replacetag($replacetag) {
	return array("<head>","after");
}

Filter: autoptimize_filter_js_replacetag

add_filter('autoptimize_filter_js_replacetag','my_ao_override_js_replacetag',10,1);
/**
 * Where in the HTML optimized JS is injected.
 *
 * @param array $replacetag, containing the html-tag and the method (inject "before", "after" or "replace")
 * @return array with updated values
 */
function my_ao_override_js_replacetag($replacetag) {
    return array("<injectjs />","replace");
}

Filter: autoptimize_js_do_minify

add_filter('autoptimize_js_do_minify','my_ao_js_minify',10,1);
/**
 * Do we want to minify?
 * If set to false autoptimize effectively only aggregates, but does not minify.
 *
 * @return: boolean true or false
 */
function my_ao_js_minify() {
	return false;
}

Filter: autoptimize_css_do_minify

add_filter('autoptimize_css_do_minify','my_ao_css_minify',10,1);
/**
 * Do we want to minify?
 * If set to false autoptimize effectively only aggregates, but does not minify.
 *
 * @return: boolean true or false
 */
function my_ao_css_minify() {
   return false;
}

Filter: autoptimize_js_include_inline

add_filter('autoptimize_js_include_inline','my_ao_js_include_inline',10,1);
/**
 * Do we want AO to also aggregate inline JS?
 *
 * @return: boolean true or false
 */
function my_ao_js_include_inline() {
	return false;
}

Filter: autoptimize_js_moveable

add_filter('autoptimize_js_moveable','my_ao_js_js_moveable',10,1);
/**
 * When 'Also aggregate inline JS?' option is not used, this filter moves
 * all of the movable script tags at the end.
 * Example usage: when the inline scripts contain variables changing on all
 * pages, aggregating them causes each page to have its own separate 
 * concattenated file, which is less than ideal because it doesn't leverage
 * caching. Moving them at the end can significantly improve the browser's
 * parser performance. The passed string values of 'first' / 'last' controls
 * whether the inline and 3rd party movable scripts are added directly before
 * or after the concattendated file.
 * @return: string 'first', 'last'
 */
function my_ao_js_js_moveable() {
	return 'first';
}

Filter: autoptimize_css_include_inline

add_filter('autoptimize_css_include_inline','my_ao_css_include_inline',10,1);
/**
 * Do we want AO to also aggregate inline CSS?
 *
 * @return: boolean true or false
 */
function my_ao_css_include_inline() {
    return false;
}

Filter: autoptimize_filter_css_defer_inline

add_filter('autoptimize_filter_css_defer_inline','my_ao_css_defer_inline',10,1);
/**
 * What CSS to inline when "defer and inline" is activated.
 *
 * @param $inlined: string with above the fold CSS as configured in admin
 * @return: updated string with above the fold CSS
 */
function my_ao_css_defer_inline($inlined) {
	return $inlined."h2,h1{color:red !important;}";
}

Filter: autoptimize_separate_blog_caches

add_filter('autoptimize_separate_blog_caches','__return_false',10,1);
/**
 * Do not separate cache folders in multisite setup.
 */

autoptimize's People

Contributors

futtta avatar phc369 avatar zytzagoo avatar jeffpyebrook avatar pedro-mendonca avatar mehigh avatar gonzomir avatar szepeviktor avatar dtbaker avatar asadkn avatar nextend avatar macbookandrew avatar stuarteske avatar harrymilatz avatar wvega avatar eri-trabiccolo avatar presskopp avatar arttse avatar kevinptt0323 avatar synthetiv avatar junaidbhura avatar fjorgemota avatar draikin avatar iamdharmesh avatar jellycode avatar bjork avatar

Watchers

James Cloos avatar Sam Katakouzinos avatar

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.