• Resolved birken

    (@birken)


    hello, i am a super newbie i just installed an cdn image thingi. And it have an option like this:

    ENABLE NETWORK BASED OPTIMIZATION
    ImageKit can change image quality based on the connection speed of end user device.
    You will need to use service worker on your website to use this feature.

    // copy paste the below line inside your service worker code loaded with the root scope
    importScripts("https://runtime.imagekit.io/mysite/v1/js/network-based-adaption.js?v=" + new Date().getTime());

    so my question can use your plugin for this, to add the code some were in pwa? or somewhere else i have no idea?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    Yes, you can include that in the service worker using code like this:

    add_action(
    	'wp_front_service_worker',
    	static function ( WP_Service_Worker_Scripts $scripts ) {
    		$scripts->register(
    			'imagekit-io',
    			[
    				'src' => function () {
    					return 'importScripts("https://runtime.imagekit.io/mysite/v1/js/network-based-adaption.js?v=" + new Date().getTime());';
    				}
    			]
    		);
    	}
    );

    This can go in your custom theme’s functions.php or in a custom plugin.

    Thread Starter birken

    (@birken)

    super thx Weston,

    is it a way to test this?

    Plugin Author Weston Ruter

    (@westonruter)

    I don’t understand.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘is possible to add this code some where?’ is closed to new replies.