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.

    1 Hook

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    This function has no filter hooks available. Request one?

    Actions
    "qm/info"
    Need a new action hook? Request one here.

    PHP
            public function is_save_data(){
                if ( isset($this->super->server['HTTP_SAVE_DATA']) && stristr($this->super->server['HTTP_SAVE_DATA'], 'on') !== false ){
                    $this->once('is_save_data', function(){
                        do_action('qm/info', 'User prefers to save data');
                    });
    
                    return true;
                }
    
                return false;
            }
    

    Override

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