Support » Plugin: Inline Google Spreadsheet Viewer » Find the plugin load js and css on every page rather than only on ones are used

  • codydoby

    (@codydoby)


    The pagespeed tool of Google, i.e., https://developers.google.com/speed/pagespeed/insights/ tells me that “A plugin should only enqueue a stylesheet if it is actually used on the page.”

    But our plugin loads the js and css on all pages of website even if on the one there is no gdoc is used.

    I want to know how to modify the plug-in code to optimize this situation for me.

Viewing 1 replies (of 1 total)
  • Thread Starter codydoby

    (@codydoby)

    I am tring to do this bad thing but happily it works for me. For now it only import css and js on the posts that I use gdoc

    I modified the addFrontEndScripts () in inline-gdocs-viewer.php

    
    foreach ( $scripts as $handle => $script ) {
    	// use the js only on the those two posts: id=1 and 1360
    	if ( is_single( array( 1, 1360 ) ) ) {
    		wp_enqueue_script(
    			$handle,
    			$script['src'],
    			( isset( $script['deps'] ) ) ? $script['deps'] : array()
    		);
    	}
    }
    
    • This reply was modified 5 months ago by codydoby.
    • This reply was modified 5 months ago by codydoby.
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.