Custom Fields
Re-Envisioned
Support MB Blocks basic metabox block and loads of http requests?

  • Creator
    Topic
  • #30679
    Resolved Nicholas Cox
    Participant

    Hi, I have created a basic metabox and have tested adding a title field. When I go to test it on the front end of the website I get loads of HTTP requests for JS/CSS files.

    This is my basic metabox block...

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $meta_boxes[] = [
            'title'           => 'Hero Content',
            'id'              => 'hero-content',
            'description'     => 'A custom hero content block',
            'type'            => 'block',
            'icon'            => 'awards',
            'category'        => 'layout',
            'context'         => 'side',
            'render_template' => get_template_directory() . '/blocks/hero/template.php',
            'supports' => [
                'align' => ['wide', 'full'],
            ],
    
            // Block fields.
            'fields'          => [
                [
                    'type' => 'text',
                    'id'   => 'title',
                    'name' => 'Title',
                ],
            ],
        ];
        return $meta_boxes;
    } );

    Then I create a new page in WordPress and just include the test block above...

    test block

    Then when I visit the front end of the site. I see all of the following http requests. I do not need any of these CSS/JS files. I assume the http requests would only include dependencies I have specified in the block settings? or that are required for the block to work in the front end?

    http requests

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #30689
    Long Nguyen
    Moderator

    Hi,

    Can you please share a sharper screenshot? I do not see the URL on the last image. FYI, the extension MB Blocks does not require loading any CSS and JS files on the frontend. It might come from another plugin, the theme, or WordPress itself.

    #30693
    Nicholas Cox
    Participant

    Hi

    Sorry it is was clear before I uploaded it. Here is a new image of the inspector tab. You can see all I am calling is one metabox block and nothing else.

    inspector

    Also I have no other plugins installed, just my own plugin (Drip Create Plugin). If I remove the metabox block all of the JS/CSS are no longer called. I have created a test page with only one metabox block and no other information, see below.

    no-metabox-block

    Thanks

    Nick

    #30694
    Nicholas Cox
    Participant

    Just an update, I was up late last night and forgot that I had a script in my footer.php page which was being called (I left in in there as I was doing a test). This is the bit of code causing all of those CSS/JS to be loaded, but not sure why?

    $request = WP_REST_Request::from_url( 'http://localhost/freestuffgroup/wp-json/wp/v2/posts' );
    $request->set_method( 'GET' );
    $response = rest_do_request( $request );
    $jsonStr = json_encode($response->get_data());
    //var_dump( $jsonStr );
    

    Thanks

    Nick

    #30698
    Long Nguyen
    Moderator

    Hi,

    Thanks. So if you remove the code in the file footer.php and the CSS/JS files won't be loaded, right? I don't think so.

    Looking at this screenshot https://ibb.co/LC0hQ8R, when you use the shortcode Frontend Submission, all the CSS/JS files that the fields or the form need to use will be loaded on that page.

    #30722
    Nicholas Cox
    Participant

    Hi

    Thanks for the quick response. You are right, thanks for this, I assumed as I was not calling the post content and just the title, that in theory, it would not load all the CSS/JS.

    This has now been resolved.

    Thanks

    Nick

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.