Overview
If you're like me, when you're building web pages, you work locally before publishing your work to the web. While this is helpful in ensuring you don't publish bad code and break something, it also has its disadvantages in that not everything functions the same locally as is does in the great outdoors, so to speak.
What Happened?
I was working on my portfolio page for class and I needed to include a downloadable link for my resume. I later found out that it was fine to have my resume open in the browser, as long as there was a link to download it, which with a pdf, there is. However, I had already invested time trying several different things to get my resume to automatically download instead of opening in the browser first.
I found this article on w3schools and it seems pretty simple to just add the download attribute to my a tag, which I did. I even tried to add a file name to the download attribute as well. No matter how I manipulated the a tag, my resume just continued to open in the browser instead of download.
Next Steps
I reached out to the instructor and found that it was OK for my resume to open in the browser, as long as there was an option to download it. I added the target attribute to my a tag and set it to equal _blank so that at the very least, my resume would open in a new tab and the viewer would then have the option to download locally, if they wished.
Even though this would suffice, I was dumbfounded as to why it didn't work. I had followed all of the steps and spent time trying several different things to no avail. Even though I fulfilled the requirements for the assignment, my curiosity got the best of me and I wanted to get it to function correctly.
Voilà!
In building my portfolio and testing, I was doing everything locally. I try to at least have the majority of the framework in place before I push things to GitHub. Once I finally pushed my first version to GitHub and published it, I went through all of the elements and links on the page to make sure everything was working correctly. When I got to my resume link and clicked it, rather than open in a new browser tab, it downloaded directly to my download folder. 🤦♀️
Lesson learned: the download attribute on the a tab only works when the website it published. At least for me, it did not work when I viewed the page locally.
Second lesson learned: Since I'm not really working in a live environment until I officially submit my homework, push early and more often. Don't ever spend time trying to fix something locally before testing it published first.
Behind the Curtain
This is what I had initially tested that kept opening the pdf in the browser. I'm sure if I replaced what I currently have with this, it would work in the published version:
<a href="./assets/download/christina-resume.pdf" download>Resume</a>
My final code looks like this. I think I can probably remove the target attribute in a future update:
<a href="./assets/download/resume.pdf" target="_blank" download="Christina-resume.pdf">Download Resume</a>
Something to note: based on a suggestion from my instructor, I changed the link text from Resume to Download Resume so that the user would expect the resume to download instead of open in the browser.