-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Loading assets only when necessary #152
Comments
So, in theory the following should work:
Should work perfectly fine? |
your solution won't work! please read the docs carefully... the filter hook is not intended for this kind of actions do dequeue the resources take a look into the DRI implementation btw. i've just take a dive into the sources....theoretically it should also work with the compat mode because in the newer releases DRI is implemented as additional filter |
I had a feeling it wouldn't work! When I enable DRI and navigate to a page with code blocks, they're not formatted at all 😞 For example: Looking at the DRI implementation, it looks like my use-case is always validating as false (I assume, that's due to the fact that the code blocks in use on this article, for example, are "non-Enlighter" code blocks and therefore "compatibility"?) |
your example page works currently fine. do you've disabled dri right now ? |
I tried running the same dequeue's as follows (I know this is janky - but I was just trying):
But the problem was, I was getting a few console errors, due to the inline config still being appended |
i will try to reproduce the error (dri + compat mode) |
i'm a bit confused... the code blocks on this particular page are generated by Gutenberg "Code" block... this format is not supported by the compat mode.... why does the highlighting work ? did you changed the CSS selectors ? <pre class="wp-block-code"><code>function </code></pre> expected behaviour: the compat mode does only match code with the following structures (e.g. used by jetpack markdown): <pre><code>function </code></pre>
<pre><code class="php">function </code></pre> |
So it's a "partial working" for the blocks when DRI is disabled - I still need to get some time to go through and sort all of my blocks and convert them up to Enlighter blocks |
that's the issue: by changing the selectors, the EnlighterJS (javascript) library will highlight ALL elements which are matching. the to use DRI, the content has to be modified/handled by the Enlighter Plugin (WordPress) - you skipped this step - therefore it cannot work.. please use the default selectors and add a custom content filter sry @willstocks-tech but the Enlighter plugin is very complex... |
i'm currently adding additional compat modes for crayon and Gutenberg style codeblocks |
Ahhhh, OK - so if I switch the selectors back to default and then go through all of my posts and where I have a snippet, convert the block to an Enlighter block - that will take care of the DRI "issue"? No worries @AndiDittrich!!! I completely understand - it is incredibly complex! I have a habit of breaking complex things 😉 lol! I will convert the selectors back to default and will go through my articles. I've now fully uninstalled Crayon (it's not PHP 7.3 compatible!!!) so the code blocks now "orphaned". It looks like Enlighter is picking up some of my old Crayon blocks - https://willstocks.co.uk/powershell-get-mailboxstatistics/:
But I think that's because I'm still using pre and code as the selectors! |
I've swapped the blocks in my PHP article and have updated the selectors. It's working there fine (I need to go through all my historic stuff now!) The only thing that makes me a bit sad... inline code is now not styled - which I thought looked super cool! Because I was previously looking at only |
DRI by using EnlighterJS build-on codeblocks (Gutenberg), dialogs (TinyMCE) or shortcodes (not recommended) the DRI mechanism will work! the theory behind is pretty simple: all code tags generated by the Enlighter WordPress Plugin have the "magic" please enable DRI again (just for a short time - i will take a look on it). Inline Code it's still supported by the TinyMCE plugin.... the Gutenberg Plugin is a bit weird in case of adding custom formats...(there are a lot of open issues...) i'm trying to add this feature soon |
I have excluded Enlighter from Autoptimize, as it was resulting in the JS being deferred which broke things. I will enable DRI again for you now. The blocks were "converted" from Gutenberg Code blocks to Enlighter code blocks. They work perfectly when DRI is disabled, but do not work when DRI is enabled. |
DRI now enabled - see: https://willstocks.co.uk/php-dom-manipulation-snippet/ |
|
Options:
|
that's weird...the code is setup correctly...it should work... :( i've no idea whats going on..sry another issue on your site: the attributes of the <pre class=EnlighterJSRAW data-enlighter-language=php data-enlighter-theme data-enlighter-highlight data-enlighter-linenumbers data-enlighter-lineoffset data-enlighter-title data-enlighter-group> additionally the whole markup of the page is broken by multiple html tags - i'm not sure whats going on but i believe that's another broken plugin ... try to check this on your testing page... |
I don't know if this will help or not... but I've attached the actual HTML markup that I'm seeing on my end (not logged in, browser cache cleared) |
Hmmm, OK interesting I'm with you now... view-source is showing no quotes I don't think I have anything that would affect this though... I will try turning off Autoptimize's HTML minification feature to see if that makes a difference. I'm travelling now, so will take a look when I get home (a couple of hours) |
It's weird though, because this is only an issue when DRI is enabled (I think) - when DRI is disabled, the code blocks are all formatted perfectly fine, so I assume it's working as expected??? |
i didn't have time to check this right now. i would suggest to disable all caching/opimization plugins and try it again |
Will do - I will get a test server spun up as “in theory” this is a
production site 😂
…On Mon, 25 Feb 2019 at 16:35, Andi Dittrich ***@***.***> wrote:
i didn't have time to check this right now.
i would suggest to disable all caching/opimization plugins and try it again
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#152 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Apt9Ag3cWRQp_xrNdbTtVPwvi2kayVKcks5vRBDogaJpZM4bP97i>
.
|
I disabled DRI again and formatting works as expected (as long as you clear your browser cache): https://willstocks.co.uk/php-dom-manipulation-snippet/ - I'm in the process of getting a test server setup now |
I can confirm - Autoptimize's HTML minification feature is what is stripping out quotes, however, based on the research I was doing last night, no quotes is also valid HTML:
That being said - would you like me to raise a question to Frank @ Autoptimize to find out what's what? |
I have completed the following steps:
Still, assets do not load on posts (https://willstocks.co.uk/php-dom-manipulation-snippet/) where an Enlighter Code Block exists 😞 😢 |
hi will, thanks for your effort to investigate the issue - i'm very sorry for this inconvenience i've tried to reproduce the behaviour but everything works as expected within my testing environment. best regards, Andi |
Hi Andi, Not a problem at all! I can appreciate that environments differ - not every single scenario can be tested! I'm just about to get a test environment put together, I will let you know how that gets along. For reference, I'm running PHP 7.3 - I don't know whether that makes any difference to you? Also, can I just confirm - is DRI handled here: Plugin.WordPress/class/Enlighter.php Line 201 in e5a4549
or here: Plugin.WordPress/class/ContentProcessor.php Line 142 in e5a4549
They're both very similar, I couldn't work out which one is/should be firing! |
the first one adds the the second one adds the content filter to WordPress |
OK, I have just setup a like-for-like environment: DRI is now enabled... and it seems to be working OK. I've even re-enabled Autoptimize and W3TC and it's still working OK... |
I've just changed back to my theme... it looks like it's something related to the theme - I've no idea where to start with that though, I might have a word with the theme developer to see if they have any insight! |
Hi Andi,
The devs that look after my theme have worked it out - I’ll update in the
morning (it’s 00:00 now!) but it’s to do with related posts.
I have a PR they have recommended so I’ll submit that for you tomorrow too?
…On Tue, 26 Feb 2019 at 10:04, Andi Dittrich ***@***.***> wrote:
the first one adds the dequeue filter to wp_footer in case the DRI option
is enabled AND the content filter or shortcode processor have not detected
any Enlighter code (thats just the dequeue action)
the second one adds the content filter to WordPress the_content filter
hook (thats the detection itself)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#152 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Apt9Aj9I2eQfZ9J93v89z-5Xey5KV5kcks5vRQbEgaJpZM4bP97i>
.
|
That sounds good. i assume that the changes only affects the theme |
Please see PR #153 - it's to do with the way that the plugin was/is detecting whether there's code within |
i'll check this soon but the code doesn't match the coding styles...therefore i will reject the current version... |
Thanks Andi - hopefully it makes sense what it's trying to do? I have just updated the styling ( |
Hi Andi, |
Hi @AndiDittrich
So, I was attempting to load Enlighter only on
is_single
posts - at first I tried dequeueing the assetsif ( !is_single() )
but then realised that wasn't going to work (based on previous issues opened). So I enabled DRI and that seemed to work! However, when I now navigate to a page where I have code (COMPATIBILITY!) Enlighter doesn't load. So, my question is:How can I load the Enlighter assets only on
is_single
but also where I did not exclusively use Enlighter to generate the code block?The text was updated successfully, but these errors were encountered: