Homepage not loading correctly, only after refreshing

You can change your current theme to storefront and check whether the scripts and styles are properly enquequed.
use this format to enqueque style and scripts and inspect the code for debugging

class yourPluginName {
    public function __construct() {
        add_action('wp_enqueue_scripts', array($this, 'enqueue'));
    public function enqueue() {
        wp_enqueue_script('my-js', plugins_url('/script.js', __File__));
        wp_enqueue_style('my-theme', plugins_url('/style.css', __File__));