Skip to content

Commit 976bc65

Browse files
Update widget DOM optimization (#326)
* Update widget DOM optimization * Update
1 parent 749b47b commit 976bc65

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/widgets/widget-inner-wrapper.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" />
44

5-
Elementor widgets define their own markup in the `render()` method. However, Elementor wraps each widget in two `<div>` elements; the outer `<div class="elementor-widget">` element, and the inner `<div class="elementor-widget-container">` element. These additional wrappers allow Elementor to add additional styles like background, margins, borders, motion effects, etc.
5+
Elementor widgets define their own markup in the `render()` method. However, Elementor wraps each widget in two `<div>` elements; the outer `<div class="elementor-widget">` element, and the inner `<div class="elementor-widget-container">` element. In the past, these additional wrappers allow Elementor to add additional styles and features.
66

7-
Two wrappers for each widget increases the overall DOM size, reducing page performance. To overcome this, developers can use the `has_widget_inner_wrapper()` method to control the number of wrapper elements the widget has.
7+
However, two wrappers for each widget increases the overall DOM size, reducing page performance. To overcome this, developers can use the `has_widget_inner_wrapper()` method to control the number of wrapper elements the widget has.
88

9-
By switching to a single wrapper, a widget can reduce the DOM size and optimize its footprint on the page. However, existing widgets that rely on the inner `.elementor-widget-container` wrapping element to style widgets, can maintain backwards compatibility.
9+
By switching to a single wrapper, a widget can reduce the DOM size and optimize its footprint on the page. But, existing widgets that rely on the inner `.elementor-widget-container` wrapping element to style widgets, can maintain backwards compatibility.
1010

1111
## Widget Markup
1212

13-
The current, unoptimized widget markup, includes two wrapping elements:
13+
The old, unoptimized widget markup, includes two wrapping elements:
1414

1515
```html
1616
<div class="elementor-widget elementor-widget-{widget-name}">
@@ -20,46 +20,42 @@ The current, unoptimized widget markup, includes two wrapping elements:
2020
</div>
2121
```
2222

23-
The optimized markup has only one wrapping element:
23+
The new, optimized markup, has only one wrapping element:
2424

2525
```html
2626
<div class="elementor-widget elementor-widget-{widget-name}">
2727
...
2828
</div>
2929
```
3030

31-
Elementor had previously utilized unoptimized markup. Nowadays, the only websites with unoptimized markup are those that have deactivated the "Optimized DOM" feature. When enough addons have embraced this feature, Elementor will activate it on all websites.
31+
Elementor had previously utilized unoptimized markup. Nowadays, all Elementor and Elementor Pro widgets use optimized markup. Elementor provided a transition period for external developers to adopt the optimized widget markup.
3232

3333
### Wrapping Elements
3434

35-
The number of wrapping elements that each widget needs is up to the widget developer.
35+
The number of wrapping elements required for each widget is determined by the widget developer. Elementor provided a transition period for external developers to adopt the optimized widget markup.
36+
37+
Legacy widgets that require both `<div>` wrappers, including the inner `.elementor-widget-container` wrapper, use the following method in the widget:
3638

37-
If it's a legacy widget that requires both `<div>` wrappers, as it requires the inner `.elementor-widget-container` wrapper, add the following method to the widget:
3839
```php
3940
public function has_widget_inner_wrapper(): bool {
4041
return true;
4142
}
4243
```
4344

44-
If it's a new widget that can work with only the outer `<div>` wrapper, without the inner `.elementor-widget-container` wrapper, add the following method to the widget:
45+
New widgets that can work with only the outer `<div>` wrapper, without the inner `.elementor-widget-container` wrapper, use the following method in the widget:
4546

4647
```php
4748
public function has_widget_inner_wrapper(): bool {
4849
return false;
4950
}
5051
```
5152

52-
If it's a legacy widget that was already optimized, and prefer to leave the choice to the website, based on the feature activation status, add the following method to the widget:
53+
Finnaly, widgets that do not employ the `has_widget_inner_wrapper()` function will behave like unoptimized widgets with two wrapping `<div>` elements. This behaviour may change in the future to optimize the remaining widgets.
5354

54-
```php
55-
public function has_widget_inner_wrapper(): bool {
56-
return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
57-
}
58-
```
55+
### Future
5956

60-
Finnaly, widgets that do not employ the `has_widget_inner_wrapper()` function will behave like unoptimized widgets with two wrapping `<div>` elements.
57+
Developers should plan ahead for when unoptimized widgets will stop being rendered. To avoid compatibility and styling problems, every widget should include the `has_widget_inner_wrapper()` method set to return `false`.
6158

62-
In any case, whether the experiment is active or not, developer need to think about the future when Elementor merges this feature. To prevent styling issues, make the necessary updates. Add the `has_widget_inner_wrapper()` to all the widgets.
6359
## Examples
6460

6561
### Optimized Widget DOM

0 commit comments

Comments
 (0)