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

[Feat] Optimise Video #19

Open
ManishBisht777 opened this issue Jul 1, 2023 · 16 comments
Open

[Feat] Optimise Video #19

ManishBisht777 opened this issue Jul 1, 2023 · 16 comments
Labels
enhancement New feature or request

Comments

@ManishBisht777
Copy link
Member

Description

Currently, the performance of the page due to the video player this can optimize by certain techniques which can be seen in below article

https://www.labnol.org/internet/light-youtube-embeds/27941/

Screenshots

No response

Additional information

No response

@ManishBisht777 ManishBisht777 added the enhancement New feature or request label Jul 1, 2023
@Jayakumar03
Copy link

I would love to work on this .

@ManishBisht777
Copy link
Member Author

Sure assigned to you

how ever you have to look into it, if the thing works with nextjs or not

@Vishal-raj-1
Copy link
Member

Hey @Jayakumar03 any update on this issue?

@Shyam3050
Copy link
Contributor

I will work on this issue

@ManishBisht777
Copy link
Member Author

sure @Shyam3050 assigned to you :)

@ManishBisht777
Copy link
Member Author

The issue is being unassigned due to inactivity and assigned to @Shyam3050

@Shyam3050
Copy link
Contributor

Where should I globally place the JS code for optimization?

@ManishBisht777
Copy link
Member Author

you can put it in /lib folder or any other place which you feel like suitable for this

@Shyam3050
Copy link
Contributor

Shyam3050 commented Oct 4, 2023

Hey, @Vishal-raj-1 and @ManishBisht777 Found a better solution using react-lite-youtube-embed. Can I proceed with it?

@Vishal-raj-1
Copy link
Member

@Shyam3050 It's not stable, if you are planning to use any package then go for react-youtube

@Shyam3050
Copy link
Contributor

Screenshot (119)

I need help to add these two function

function labnolIframe(div) {
var iframe = document.createElement('iframe');
iframe.setAttribute('src', 'https://www.youtube.com/embed/' + div.dataset.id + '?autoplay=1');
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('allowfullscreen', '1');
iframe.setAttribute('allow', 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture');
div.parentNode.replaceChild(iframe, div);
}

function initYouTubeVideos() {
var playerElements = document.querySelectorAll('.youtube-player');
for (var n = 0; n < playerElements.length; n++) {
var videoId = playerElements[n].dataset.id;
var div = document.createElement('div');
div.setAttribute('data-id', videoId);
var thumbNode = document.createElement('img');
thumbNode.src = '//i.ytimg.com/vi/ID/hqdefault.jpg'.replace('ID', videoId);
div.appendChild(thumbNode);
var playButton = document.createElement('div');
playButton.setAttribute('class', 'play');
div.appendChild(playButton);
div.onclick = function () {
labnolIframe(this);
};
playerElements[n].appendChild(div);
}
}

A Better Method for Embedding YouTube Videos on your Website.
Where should I put these files?
when I put any place it causes an error document not found.
in the ssr document was undefined which caused an error.
I tried this on my existing React project it works.
In next.js I am unable to understand what should I do any suggestions,s please?
I will try my best it is the most challenging and interesting issue.

@Vishal-raj-1
Copy link
Member

Screenshot (119)

I need help to add these two function

function labnolIframe(div) { var iframe = document.createElement('iframe'); iframe.setAttribute('src', 'https://www.youtube.com/embed/' + div.dataset.id + '?autoplay=1'); iframe.setAttribute('frameborder', '0'); iframe.setAttribute('allowfullscreen', '1'); iframe.setAttribute('allow', 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'); div.parentNode.replaceChild(iframe, div); }

function initYouTubeVideos() { var playerElements = document.querySelectorAll('.youtube-player'); for (var n = 0; n < playerElements.length; n++) { var videoId = playerElements[n].dataset.id; var div = document.createElement('div'); div.setAttribute('data-id', videoId); var thumbNode = document.createElement('img'); thumbNode.src = '//i.ytimg.com/vi/ID/hqdefault.jpg'.replace('ID', videoId); div.appendChild(thumbNode); var playButton = document.createElement('div'); playButton.setAttribute('class', 'play'); div.appendChild(playButton); div.onclick = function () { labnolIframe(this); }; playerElements[n].appendChild(div); } }

A Better Method for Embedding YouTube Videos on your Website. Where should I put these files? when I put any place it causes an error document not found. in the ssr document was undefined which caused an error. I tried this on my existing React project it works. In next.js I am unable to understand what should I do any suggestions,s please? I will try my best it is the most challenging and interesting issue.

@ManishBisht777 See this

@ManishBisht777
Copy link
Member Author

You can create a new client component instead of a function and use it in MDX
Since the component is client comp you can access document and window methods in it

The component takes the URL and any other field that u feel like
and you can handle things in the useEffect

@ManishBisht777
Copy link
Member Author

Hope that helps

@Shyam3050
Copy link
Contributor

@ManishBisht777 I have some issues can we do a Zoom call?
I solved almost 5 issues but this one is the most challenging for me.
I tried with react project it works but in Next.js I was unable to solve it.

@ManishBisht777
Copy link
Member Author

Quite bust lately, you can connect with other folks on discord or whatsapp grp of frontend freaks

@Shyam3050 Shyam3050 removed their assignment Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants