Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 974251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:24:23+00:00 2026-05-16T03:24:23+00:00

Is there a way in JavaScript to get the contents of a linked file

  • 0

Is there a way in JavaScript to get the contents of a linked file without making a second GET request? That is, if I have

<link rel="foo" href="bar.txt">

the browser should automatically download bar.txt. Is there any way to read its contents without getting it again (i.e. via jQuery’s $.get or similar)?


Edit

I could use a second GET request and as mentioned in the comments there likely wouldn’t be a performance hit, but this question is mainly a thought experiment: it seems like it’d be pretty standard functionality, but more and more things point to this not being possible. Is there a reason why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:24:24+00:00Added an answer on May 16, 2026 at 3:24 am

    If the tag has absolutly no other purpose than being a placeholder for the source, then the objective is to prevent the first get rather then the second 😉 By using another attribute you avoid the default behaviour.

    <link data-src='file.txt' />
    

    ‘data-…’ is a valid HTML5 attribute you can use right now, though the html will not be valid if an older doctype is declared but will still work.

    Next when using jQuery:

    $('link[data-src]').each(function(){
        var self = $(this)
        , src = self.attr('data-src');
        $.get(src, function(fileContent){
            // do stuff with fileContent
        })
    });
    

    Obviously any element will do rather then the link element when using ‘data-…’, I use this technique myself to add data in a component based architecture, lazily binding resources and meta information to components without it affecting default behaviours/renditions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way in Javascript to get a list or dump the contents
Is there a way to get the names of all the javascript function executed
Is there a way to get the a users screen size/resolutions using javascript? I
Just like in JavaScript : opener.document.getElementByName jQuery: ?? Is there any way to get
Is there no way for javascript hosted on a webserver to read a file
Is there a way to refer to a Javascript variable with a string that
is there a way to get/retrieve the value/parameters in a 'file_get_contents' in php file
Is there a way in JavaScript to compare values from one array and see
is there a way with javascript/jquery to prevent images from loading? I am building
Is there a way in JavaScript for me to tell whether a resource is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.