Skip to Content

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.

Source File

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

No Hooks

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

            return false;
        }

Override

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