Skip to Content
Menu

is_save_data()

Check if the user has requested to use less data via the Save Data header.

PHP March 12, 2018

Usage

PHP
nebula()->is_save_data()

Parameters

This function does not accept any parameters. Is this incorrect?

Examples

HTML
<?php if ( !nebula->is_save_data() ): ?>
    <video>
        <!-- Load "expensive" video here -->
    </video>
<?php else: ?>
    <img src="lite.jpg" /><!-- Load a smaller image instead -->
<?php endif; ?>
CSS
#hero {/* Do lots of cool stuff */}
.save-data #hero {/* Do fewer crazy things */}

Demo


No Save Data header found, normal data usage ok.

Additional Notes

A class of save-data is added to the <body> tag so that stylesheets and JavaScript can look for it too.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Optimization.php on line 151.

    No Hooks

    This function does not have any filters or actions available. Request one?
    PHP
            public function is_save_data(){
                if ( isset($this->super->server['HTTP_SAVE_DATA']) && stristr($this->super->server['HTTP_SAVE_DATA'], 'on') !== false ){
                    return true;
                }
    
                return false;
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?