Hi Nayeem,
I see this: Update! Enhanced System Optimization and Compatibility Assurance Update, but I’m curious what was optimized?
In my situation, to avoid loading the same styles and JS files over and over for every package on a page, I have to find a way to only call [doc_preview] when I’m actually wanting to display the PDF Viewer.
For example on this page: https://dev.neonet.org/policies/
Every time the “view Policy” button is displayed, it calls all.css, viewer.css, viewer.js, etc. etc. etc. It’s causing issues with our overall site performance and we must find a better solution. Those files only need to be present on the page one time, and they only need to be present on pages that use this feature.
They seem to be pulled into the page through the inclusion of the [doc_preview] shortcode. If I can modify my modal buttons so that they call a separate php file that does 2 simple things… passes the package ID on the URL, and loads the [doc_preview] shortcode, I should be able to resolve this issue.
Thanks!
-Scott
Hi Nayeem,
This continues to be a problem, so I’ve been researching some alternate ways to prevent loading all of the repeating files causing unnecessary server calls, on just one page we have 300+ that can be eliminated if I can simply load those styles and JS files once.
Currently I am exploring a link template that I can apply to my Packages by category Elementor widget whereby instead of including [doc_preview] in the link template, which then causes all of the repeating files to load for every package in the category, I would like to make it so that the modal button calls another script/page and passes in the package ID where that new page/script loads [doc_preview]. This will ensure that regardless of how many packages are in the category and displayed on a single page, none of the other resources will be called until you click the modal button.
However, in my new page/script, even though I can confirm that WPDM and the WPDM PDF Viewer plugins are active, the [doc_preview] shortcode is not registered. Can you provide any guidance on how to ensure that shortcode is registered?
Also, I see WPDM PDF Viewer 3.1.0 just released, are there any details to the changelog available?
Thanks!
-Scott
Hi Nayeem,
Can you clarify what it is you think I’m wishing to have embedded? Based on what I pasted above, I just want to not link to the CSS and JS resources and instead enqueue them whereby the WordPress engine will insure they only load once regardless of how many packages exist on the page.
Change these links:
<link rel=”stylesheet” href=”<?= plugins_url(‘wpdm-pdf-viewer/pdfjs/web/viewer.css’) ?>”>
<link rel=”stylesheet” href=”<?= WPDM_ASSET_URL ?>bootstrap/css/bootstrap.min.css”>
<link rel=”stylesheet” href=”<?= WPDM_ASSET_URL ?>css/front.min.css”>
<link rel=”stylesheet” href=”<?= WPDM_FONTAWESOME_URL ?>”>
To enqueue:
wp_enqueue_script(‘pdf-js’, ‘path/to/pdf.js’, array(), ‘version’, true);
wp_enqueue_script(‘pdf-worker-js’, ‘path/to/pdf.worker.js’, array(‘pdf-js’), ‘version’, true);
wp_enqueue_script(‘viewer-js’, ‘path/to/viewer.js’, array(‘pdf-js’), ‘version’, true);
I believe once it is enqueued it won’t call it again, correct?
Thanks!
-Scott
Hi Nayeem,
It actually is an issue, under light load, it can appear to load up quickly. But try viewing one of the PDF modals as soon as the page loads. It sits and spins waiting for the rest of the page content to load, which happens to the be the 5+ linked resources the packages by category template is loading repeatedly for every package.
I have other pages, behind the login screen, that are significantly worse because they have 20 or so linked PDFs. Again, 20 packages and 5+ files per package being called from the server. It drives up memory and CPU usage and makes for a poor customer experience overall.
Unless I’m mistaken, it’s actually a pretty easy fix if the code simply enqueues the files once and doesn’t reference them by links.
Thanks,
-Scott
Hi Nayeem,
The way it works, as a midday pop-up, iframe, etc is actually fine.
What I would like to see dev fix is to not directly link to the individual JS and CSS files but rather enqueue them the way WordPress expects. With this change you can enqueue them once and they went repeat for every package. They only need to be loaded once on the page regardless of the number of packages. You’ll see significant performance impact with this fix.
Does that help?
Thanks!
Scott
Thanks, this wasn’t looking like it was posting for some reason, you can close this one and we can work in the other thread. ๐
Hi Nayeem,
I’m using [doc_preview] in the templates, thanks!
-Scott
Hi Nayeem,
Checking on this issue as well, thanks so much!
-Scott
Hi Nayeem,
Is the full URL that was attached captured and identified by a variable I could pull into my template so I can embed that YouTube link? Right now I am using the title and so my users have to fix the title with the full URL for this to work. If the URL exists in another field and I can use that, that would suffice.
Thanks!
-Scott
Awesome, thank you so much!
-Scott
Hi Nayeem,
Here are two screenshots:
This is the page where we’ve used multiple packages by category:
This is the dev-tools output (a sample) where there are 700+ server requests and you can see all of the repeating resources:
Here is the header of /wp-content/plugins/wpdm-pdf-viewer/tpls/pdf-viewer.php showing resource links as opposed to enqueuing the scripts just once. With the links used, they are getting repeated:
<?php
/**
* User: shahnuralam
* Date: 9/17/17
* Time: 2:14 AM
*/
if(!defined('ABSPATH')) die();
$pdf = isset($_GET['__wpdm_pdf_viewer'])?esc_attr($_GET['__wpdm_pdf_viewer']):'';
$_GET['file'] = $pdf;
?>
<!DOCTYPE html>
<html dir="ltr" mozdisallowselectionprint moznomarginboxes>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="google" content="notranslate">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PDF Viewer</title>
<link rel="stylesheet" href="<?php echo plugins_url('wpdm-pdf-viewer/assets/css/viewer.css'); ?>">
<link rel="stylesheet" href="<?php echo WPDM_BASE_URL; ?>assets/bootstrap3/css/bootstrap.css">
<link rel="stylesheet" href="<?php echo WPDM_BASE_URL; ?>assets/css/front3.css">
<script src="<?php echo plugins_url('wpdm-pdf-viewer/assets/pdfjs/pdf.js'); ?>"></script>
<script src="<?php echo plugins_url('wpdm-pdf-viewer/assets/js/viewer.js'); ?>"></script>
<style>
Here’s the header of viewer.php – wp-content/plugins/wpdm-pdf-viewer/tpls/viewer.php
<?php
$file_info = explode("|", $_GET['__wpdm_pdf_viewer']);
$pid = wpdm_valueof($file_info, 0);
$fileid = wpdm_valueof($file_info, 1, '');
do_action("wpdm_before_render_pdf_viewer", $pid, $fileid);
?><!DOCTYPE html>
<!--
Copyright 2012 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Adobe CMap resources are covered by their own copyright but the same license:
Copyright 1990-2015 Adobe Systems Incorporated.
See https://github.com/adobe-type-tools/cmap-resources
-->
<html dir="ltr" mozdisallowselectionprint>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="google" content="notranslate">
<meta name="robots" content="noindex">
<meta name="robots" content="nofollow">
<title>PDF.js viewer</title>
<?php \WPDM\__\Apply::uiColors(); ?>
<link rel="stylesheet" href="<?= plugins_url('wpdm-pdf-viewer/pdfjs/web/viewer.css') ?>">
<link rel="stylesheet" href="<?= WPDM_ASSET_URL ?>bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="<?= WPDM_ASSET_URL ?>css/front.min.css">
<link rel="stylesheet" href="<?= WPDM_FONTAWESOME_URL ?>">
<script>
Does that help? You can see this here: https://dev.neonet.org/policies/
Thanks!
-Scott
I’m curious if there is an option to use hooks or theme templates or similar option to over ride the default repetitive loading of styles and js files?
Thanks!
-Scott
One option might be to enqueue the scripts and CSS so they only load once?
function my_custom_enqueue_scripts() {
wp_enqueue_script('pdf-js', 'path/to/pdf.js', array(), 'version', true);
wp_enqueue_script('pdf-worker-js', 'path/to/pdf.worker.js', array('pdf-js'), 'version', true);
wp_enqueue_script('viewer-js', 'path/to/viewer.js', array('pdf-js'), 'version', true);
}
add_action('wp_enqueue_scripts', 'my_custom_enqueue_scripts');
Since that post seemed to take, here’s the issue.
Hello,
When using the PDF Viewer Add-On in a template used in Packages by Category (Elementor), the following files get repeated for every button presented. It seems the code could be written to enqueue the scripts and CSS once which would have a significant impact on page performance. Is this something we can do on our own, or would this fix need done on your end?
wp-content/plugins/wpdm-pdf-viewer/pdfjs/web/viewer.css
wp-content/plugins/download-manager/assets/bootstrap/css/bootstrap.min.css
wp-content/plugins/download-manager/assets/css/front.min.css
https://use.fontawesome.com/releases/v6.2.0/css/all.css
wp-content/plugins/wpdm-pdf-viewer/pdfjs/build/pdf.js
wp-content/plugins/wpdm-pdf-viewer/pdfjs/web/viewer.js
wp-includes/js/jquery/jquery.js
wp-includes/js/jquery/jquery.form.js
wp-content/plugins/wpdm-pdf-viewer/pdfjs/web/locale/locale.properties
Have 20 packages in a category and then call those files for all 20 packages is quite taxing.
Perhaps one option would be to enqueue the scripts as opposed to link to them within the HTML attributes in the code?
Look forward to your suggestions.
Apologies if this is a dupe, I’m not seeing it post to the forum.
Kind regards,
-Scott
Hello, I’m trying to post a support request and it’s not making it into the forum. It has to do with this thread and the PDF Viewer Add on.
Hello, just checking on this issue. Thanks!
-Scott
Hi there,
Just checking back on this issue?
Thanks!
-Scott
Hi Nayeem,
Wanted to elevate this again and give in an indication of how troubling it is.
Doesn’t seem like the img tool in here supports embedded images:
I have to keep clicking through one template at a time to find the latest one added, or another if I want to see a different look and feel.
Kind regards,
-Scott
Hi Nayeem,
Please press them again as this is some pretty critical functions of the software and it seems like it’s not too complicated of a fix (sort functions on the queried data). I would really hope this is something they can fix as a core feature of the software quickly.
Kind regards,
-Scott
Hi Nayeem,
I need a timeline as to when this will be fixed, can you tell me when that will be available?
Thanks,
-Scott
Hello, any update on this fix?
Kind regards,
-Scott
Hello, it has been almost a month and this is a significant issue for us, is there any timeline for when we can expect a fix?
Kind regards,
-Scott
Hello, just checking on the status of this issue and curious if there is an estimated timeframe it will be fixed? We currently have a number of documents that need to be sorted alphabetically and have no means of doing that. Thanks!
Hello, just checking on the status of this issue and curious if there is an estimated timeframe it will be fixed? I have users that will begin using this soon and at the moment they have no visibility of the available templates. They currently have to select each one to see if it’s the one they want. Thanks!
Hello, just checking on the status of this issue and curious if there is an estimated timeframe it will be fixed? Thanks!