-
Notifications
You must be signed in to change notification settings - Fork 21
Optimize performance of regex for adding loading
attribute
#2
Comments
Generally (historically) having line breaks between HTML tag attributes doesn't work in user added content (because wpautop). It is also mentioned in the WP coding standards (I think) as being "not best practice" when outputting HTML from PHP. Wouldn't mind slowing things down a little bit by looking for Also thinking that a tiny optimization would be to not capture the actual space character ( |
Right. Looked at this a bit. Ideally there should be a filter that runs on each There are few "requirements" that make this somewhat more involved/a bit harder:
|
Also, in order to be able to use that new filter for adding |
What we need to here partially depends on the outcome of #3. If As long as the filter that we expose is |
Done via #23 |
As previously pointed out by @azaozz, we should make sure we minimize the number of regular expressions used to modify content (via filters such as
the_content
).A couple of things:
wp_lazy_load_content_media()
should no longer run apreg_match()
for each match frompreg_replace_callback()
. Thepreg_replace_callback()
regular expression should be modified to cover both parts.wp_make_content_images_responsive()
.img
tags, we could use that as is.img
with(' . implode( '|', $tags ) . ')
to cover different tags. In this case, the callback logic would need to account for that and only perform replacements for the right tags.wp_make_content_images_responsive()
only looks atimg
, notimg(\s)
like we do. We added that based on review by @westonruter - I think it makes the regex more robust, but it could also be considered overkill, given how WordPress image tags are typically printed.It would be great to do some profiling on how potential changes here would affect performance for content that contains a very high number of relevant tags.
The text was updated successfully, but these errors were encountered: