admin-ajax.php slow website, how to fix

Question

I have a function in my wordpress that load a dynamic css. I checked that this admin-ajax.php call made the website slow (+5s) about.

add_action( 'wp_enqueue_scripts', 'theme_custom_style_script', 12 );

function theme_custom_style_script() {
    wp_enqueue_style( 'dynamic-css', admin_url('admin-ajax.php').'?action=dynamic_css', '');
}

add_action('wp_ajax_dynamic_css', 'dynamic_css');

function dynamic_css() {
    require( get_template_directory().'/css/custom.css.php' );
    exit;
} 

Can i save the output of this file in a folder each time i make an edit on admin , and load such a css link instead of load everytime via admin-ajax ? or call in different way to avoid this issue ?
Thanks

0
user3309614 8 months 2020-12-09T01:10:21-05:00 0 Answers 7 views 0

Leave an answer

Browse
Browse