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
Pull Scripts out of PHP & Begin removing jQuery dependency #236
Conversation
08d7f75
to
22f6e43
Compare
src/lib/init-api/index.js
Outdated
function uuidProfileCall( { apikey, uuid } ) { | ||
const profileScript = document.createElement( 'script' ); | ||
profileScript.src = `https://api.parsely.com/v2/profile?apikey=${ encodeURIComponent( | ||
apikey | ||
) }&uuid=${ uuid || '' }&url=${ window.location.href }&callback=&_=${ +new Date() }`; | ||
document.querySelector( 'head' ).appendChild( profileScript ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part I'm least confident about. I'm attempting to replace this "jsonp" call:
wp-parsely/parsely-javascript.php
Lines 24 to 32 in 14c342a
function uuidProfileCall() { | |
var rootUrl = 'https://api.parsely.com/v2/profile?apikey=<?php echo esc_html( $parsely_options['apikey'] ); ?>'; | |
var uuid = '&uuid=' + PARSELY.config.parsely_site_uuid; | |
var requestUrl = rootUrl + uuid + '&url=' + window.location.href; | |
jQuery.ajax({ | |
url: requestUrl, | |
dataType: "jsonp" | |
}); | |
} |
...which isn't obvious to me how it's used or what it does. @hbbtstar -- can you shed any light on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the internal P2 post, CORS support in browsers is now enough, that JSONP isn't needed any more.
e2e260c
to
68c6bf9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love where this is going!
Added a few comments, including 3-4 items that we may want to spin up into separate issues/PRs, if you don't want to address them in this one.
wp-parsely.php
Outdated
} | ||
|
||
if ( $handle === 'wp-parsely-tracker' ) { | ||
$tag = preg_replace( '/ id=(\"|\')wp-parsely-tracker-js\1/', ' id="parsely-cfg"', $tag ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know why this change of ID is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't know. This is another case of trying to not break anything without understanding why it is the way it is.
@hbbtstar -- any thoughts as to the necessity of having particular id
attributes to the script
tags?
…ode w/ wp functions
* pull PARSELY_PLUGIN_URL into a constant & ref in the test * cover multisite as well * drop the $parsely_html file since scripts are no longer printed directly
…instead-of-jsonp Convert Profile API call to simple XHR - no more JSONP
This is the first pass at pulling the plugin JavaScript out of PHP files and into enqueued assets.
The widget script is not included in this change as this PR was already getting pretty large. In addition, rewriting it with vanilla JavaScript is not a trivial effort and we're considering re-working it anyhow.
As such, this does not fully complete #134 or #158, but it's at least a step in that direction.
Additionally, we're able to use the WordPress i18n tooling to wrap a string in the Admin page JS for translation (see 3c62c8d). Again, it doesn't fully satisfy #160, but it paves the way for doing so.
To Test
Automated Tests
Building the Assets
Test the plugin