Skip to content
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

Update shareon.js to include LinkedIn image refresh #93

Closed
wants to merge 3 commits into from

Conversation

lisaschumann
Copy link

LinkedIn url has to include "&latest" so the latest url preview is being used not the cached one.

LinkedIn url has to include "&latest" so the latest url preview is being used not the cached one.
@kytta kytta self-requested a review October 4, 2023 17:06
src/shareon.js Outdated
@@ -18,7 +18,7 @@ import "./shareon.css";
*/
const urlBuilderMap = {
facebook: (d) => `https://www.facebook.com/sharer/sharer.php?u=${d.url}${d.hashtags? `&hashtag=%23${d.hashtags.split('%2C')[0]}` : ''}`,
linkedin: (d) => `https://www.linkedin.com/sharing/share-offsite/?url=${d.url}`,
linkedin: (d) => `https://www.linkedin.com/sharing/share-offsite/?url=${d.url}${encodeURIComponent('?latest')}`,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you have replaced &latest with this? Does the query parameter need to appear on the URL being shared (e.g., //shareon.js.org/?latest) or on the final LinkedIn URL?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did more testing and the solution is to append the current time to the end of the url (encoded) so that LinkedIn regards it as a new url altogether and fetches the latest preview.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added ${encodeURIComponent('?' + new Date().getTime())}

Appending current time to url so that LinkedIn regards it as a new url and fetches the latest preview.
@kytta
Copy link
Owner

kytta commented Oct 26, 2023

Just did more testing and the solution is to append the current time to the end of the url (encoded) so that LinkedIn regards it as a new url altogether and fetches the latest preview.

Oh, I think I now understand, what is happening here: LinkedIn caches the URL once they see it, and subsequent updates to the page (esp. its OGP tags) do not get displayed.

I am sorry, but this is out of scope of Shareon. I do not want to fix the peculiarities of other social networks, especially when it requires changing the URL of the page — I will never ever do this.

Thank you a lot for the great contribution, but I am afraid I can't merge it :/

@kytta kytta closed this Oct 26, 2023
@lisaschumann
Copy link
Author

lisaschumann commented Oct 30, 2023

@kytta completely understand! It is strange that it would not update it on LinkedIn's side for the same url. Thanks for considering it! For now, I am passing in from our side as a workaround (in case someone else is having the same issue like us where we are quite dependent on an updated preview image)

const currentTime = new Date().getTime();
const shareUrl = `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent('https://domain.com/' + '?' + currentTime)}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants