using php to check is a javascript file has been loaded?

前端 未结 2 693
悲&欢浪女
悲&欢浪女 2021-01-21 15:20

Can I use a script to check if a JS file is loaded?

I have a function, which places a form on a page with javascript controls. I don\'t know where the user will use th

2条回答
  •  时光取名叫无心
    2021-01-21 16:11

    You should have an asset management system in your PHP to see whats being included into the page.

    Ultra simple example (derived from link):

    ';
        }
        static function render_content() {
            echo self::$content;
        }
        static function read_content($file) {
            ob_start();
            require $file;
            self::$content = ob_get_clean();
        }
        static function render_layout($file) {
            require $file;
        }
        static function add_js($js) {
            if (!in_array($js, self::$js_assets)) {
                self::$js_assets[] = $js;
            }
        }
    }
    
    Page::add_js('/javascripts/application.js');
    Page::read_content('view.php');
    Page::render_layout('layout.php');
    ?>
    

    layout.php:

    
        
        
            
    
            

    view.php:

    Hello World!'); ?>
    

    Hello

    World

提交回复
热议问题