basic metabox block and loads of http requests?
- This topic has 5 replies, 2 voices, and was last updated 3 years, 7 months ago by
Nicholas Cox.
-
AuthorPosts
-
September 9, 2021 at 5:10 PM #30679
Nicholas Cox
ParticipantHi, 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...
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?
Thanks
September 10, 2021 at 11:32 AM #30689Long Nguyen
ModeratorHi,
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.
September 10, 2021 at 2:27 PM #30693Nicholas Cox
ParticipantHi
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.
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.
Thanks
Nick
September 10, 2021 at 2:40 PM #30694Nicholas Cox
ParticipantJust 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
September 10, 2021 at 9:51 PM #30698Long Nguyen
ModeratorHi,
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.
September 13, 2021 at 3:44 PM #30722Nicholas Cox
ParticipantHi
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
-
AuthorPosts
- You must be logged in to reply to this topic.