Plugin being picked up on GTmetrix
-
Hi,
I’ve used the plugin for a couple of month and have got it to work as I need. It’s a great plugin.
Now that I have my site ready, I was running it through Gtmetrix. I found it reporting the following:
————
The following resources are missing a cache validator. Resources that do not specify a cache validator cannot be refreshed efficiently. Specify a Last-Modified or ETag header to enable cache validation for the following resources:https://mywebsite.com/?cp_cff_resources=public&ver=4.1.1
————I think this relates to the Calculated Field Form. If it is, can you help me understand what the plugin is trying to do, and whether this is something that can be addressed?
I am not a coder, and a relative WordPress newbie.
Thanks in advance for your help.
https://www.ads-software.com/plugins/calculated-fields-form/
-
Hi, just a quick addition. Gtmetrix is also showing this in Keep-Alive:
————
The host should enable Keep-Alive. It serves the following resources.https://mywebsite.com/?cp_cff_resources=public&ver=4.1.1
————Thanks.
Hi,
Im not a coder so I am not able to investigate this, but if anyone is able to help I would be grateful. The issue is being picked up in multiple areas by both Page Speed and YSlow.
I think the issue is because of the ? that precedes script name (cp_cff_resources). I think it prevents the script being cached. If it is, is there a way it can be removed safely without causing disruption to the CFF plugin?
If there is additional information needed, please let me know. Alternatively, if there is another post/forum that this should be placed in, please point me in the right direction.
Cheers.
Hi,
I’m sorry for delay, I’ve not received the notification of your ticket in the support system.
We are working in a final solution but, please, follow the steps below:
1. Open the “/wp-content/plugins/calculated-fields-form/js/fbuilder-loader-public.php” file with the text editor your choice.
2. The first line of code in the file is:
<?php header('Content-Type: application/x-javascript; charset=UTF-8'); ?>
Please, paste the following code immediately after the first line of code:
<?php $lastModified=filemtime(__FILE__); $etagFile = md5_file(__FILE__); $ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false); $etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false); header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT"); header("Etag: $etagFile"); header('Cache-Control: public'); if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader == $etagFile) { header("HTTP/1.1 304 Not Modified"); exit; } ?>
Please, share with us the results of the customization ??
Best regards.
Hi,
Thanks so much for getting back. You guys do an awesome job of supporting your users.
I tried the solution suggested, but there was no change. Just to be sure, i’ve pasted a code sample from the .php file (after the change) below, in case i did something wrong:
<?php header('Content-Type: application/x-javascript; charset=UTF-8'); ?> <?php $lastModified=filemtime(__FILE__); $etagFile = md5_file(__FILE__); $ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false); $etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false); header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT"); header("Etag: $etagFile"); header('Cache-Control: public'); if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader == $etagFile) { header("HTTP/1.1 304 Not Modified"); exit; } ?> fbuilderjQuery = (typeof fbuilderjQuery != 'undefined' ) ? fbuilderjQuery : jQuery; fbuilderjQuery(function(){ (function($) { // Namespace of fbuilder $.fbuilder = $.fbuilder || {}; $.fbuilder[ 'objName' ] = 'fbuilderjQuery';
Also, I did change my site to HTTPS recently. Would this make a difference to your suggested code?
Thanks again for your help.
Hi,
You must remove the empty line, between the first and second lines of code, or the headers for etags, cache, etc won’t be functionals. Please, use the following code:
<?php header('Content-Type: application/x-javascript; charset=UTF-8'); $lastModified=filemtime(__FILE__); $etagFile = md5_file(__FILE__); $ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false); $etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false); header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT"); header("Etag: $etagFile"); header('Cache-Control: public'); if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader == $etagFile) { header("HTTP/1.1 304 Not Modified"); exit; } ?>
Best regards.
Hiya, sorry about that. I’ve used the suggested code the correct way now, but the problem persists.
To the best of my ability, I did check Chrome Developer Tools and saw the “304 Not Modified” statement appear in the header. But the ‘?’ that precedes the cp_cff_resources still shows and prevents caching (i think).
When I removed the suggested code, the header reverted to ‘200 OK’ .
Thanks.
Hi,
If you want to access to the public resources, but without parameters, the process is more complex.
First, you should modify the .htaccess file. The modification will depend of the structure of the .htaccess file in your website. In my case I’m using the following code:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (cp_cff_resources_public) /index.php?cp_cff_resources=public [L] </IfModule> # END WordPress
Second, open the “/wp-content/plugins/calculated-fields-form/cp_calculatedfieldsf.php” file with the text editor your choice. Go to the snippet of code (that appears two time in the file’s content)
( ( strpos( cp_calculatedfieldsf_get_site_url(),'?' ) === false ) ? '/?' : '&' ).'cp_cff_resources=public'
and modify this code like follow:
trim(cp_calculatedfieldsf_get_site_url(),'/').'/cp_cff_resources_public'
and that’s all.
Best regards.Hi, thanks for that. I’ve made the changes as suggested, but the form times out now.
When I look at Developer Tools, I see this error message:
GET https://mywebsite.comhttps//mywebsite.com/cp_cff_resources_public net::ERR_CONNECTION_TIMED_OUT
It looks like the website is being repeated twice in the url.
This is what I have in my .htaccess file.
# Begin modification to remove ? from calculated field form url <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (cp_cff_resources_public) /index.php?cp_cff_resources=public [L] </IfModule> # End modification to remove ? from calculated field form url
This is the edited line in cp_calculatedfieldsf.php (at approx line 510):
wp_enqueue_script( 'cp_calculatedfieldsf_buikder_script', cp_calculatedfieldsf_get_site_url().trim(cp_calculatedfieldsf_get_site_url(),'/').'/cp_cff_resources_public',array("jquery","jquery-ui-core","jquery-ui-button","jquery-ui-datepicker","jquery-ui-widget","jquery-ui-position","jquery-ui-tooltip","query-stringify","cp_calculatedfieldsf_validate_script", "jquery-ui-slider"), false, true );
This is the edited line in cp_calculatedfieldsf.php (at approx line 565):
</script> <script type='text/javascript' src='<?php echo cp_calculatedfieldsf_get_site_url().trim(cp_calculatedfieldsf_get_site_url(),'/').'/cp_cff_resources_public'; ?>'></script> <?php } }
I’m sure I’ve made a mistake. I’ve tried it twice, but same results. Can you suggest what might be wrong.
Thanks.
Hi,
The snippet of code:
wp_enqueue_script( 'cp_calculatedfieldsf_buikder_script',cp_calculatedfieldsf_get_site_url().trim(cp_calculatedfieldsf_get_site_url(),'/').'/cp_cff_resources_public',array("jquery","jquery-ui-core","jquery-ui-button","jquery-ui-datepicker","jquery-ui-widget","jquery-ui-position","jquery-ui-tooltip","query-stringify","cp_calculatedfieldsf_validate_script", "jquery-ui-slider"), false, true );
should be replaced by:
wp_enqueue_script( 'cp_calculatedfieldsf_buikder_script',trim(cp_calculatedfieldsf_get_site_url(),'/').'/cp_cff_resources_public',array("jquery","jquery-ui-core","jquery-ui-button","jquery-ui-datepicker","jquery-ui-widget","jquery-ui-position","jquery-ui-tooltip","query-stringify","cp_calculatedfieldsf_validate_script", "jquery-ui-slider"), false, true );
and the snippet of code:
<script type='text/javascript' src='<?php echo cp_calculatedfieldsf_get_site_url().trim(cp_calculatedfieldsf_get_site_url(),'/').'/cp_cff_resources_public'; ?>'></script>
should be replaced by:
<script type='text/javascript' src='<?php echo trim(cp_calculatedfieldsf_get_site_url(),'/').'/cp_cff_resources_public'; ?>'></script>
Best regards.
Hiya,
That seems to have done the trick. The ‘?’ no longer appears. Thank you so very much. Will you be incorporating these changes into the next release, or is this something that I’ll have to redo each time a new release of CFF is made?
My only other question is where is the cp_cff_resources file located? I can’t find it anywhere. I would like the location so I can manually place it on my CDN (at the moment it’s not getting there). If the file is dynamically created, is there a chance that you will be changing the plugin so it gets created/changed each time you make a change to a saved form
Thanks.
Hi,
The file is generated dynamically merging all javascript files used by the plugin’s controls.
A similar optimization will be implemented in next updates, but won’t be exactly the solution of your project, because this solution requires edit the .htaccess file, and it is not practical for all users.
Best regards.
OK. Thanks for all your help. I’ll take a look at what the next update offers. FYI, the changes you helped me make improved my PageSpeed score by 3%, and got me to 92%.
If it helps, I’d like to suggest the following:
-
1. make the removal of the ? permanent (how ever you can). This will help the plugin users overcome some Page Speed & YSlow issues
- 2. if you must make the file dynamic, can I suggest you use only the js files that are actually needed, instead of the whole library being merged. Again, this will aid in improving performance
- 3. how about generating the file only at the point when someone saves / edits a ‘form’ rather than at every time the page is hit. This way, the file can be cached and even saved to a CDN. Yep, you guessed it – to help improve performance
Thanks again for all your help. I really appreciate your efforts, and your plugin (with the exception of the performance issue) is perfect IMHO.
Thanks.
- The topic ‘Plugin being picked up on GTmetrix’ is closed to new replies.